This does Query uses XML string concatenation to get the result in the format you need.
If AssetID
or Description
can be NULL then you would have to add additional logic
SELECT '('+reverse(stuff(reverse((
SELECT A.[AssetID] +','
FROM [dbo].[AssetRegister] A
WHERE A.LocationRoomID = AR.LocationRoomID
FOR XML PATH(''))), 1, 2,''))+')'
,
'('+reverse(stuff(reverse((
SELECT A.[Description] +','
FROM [dbo].[AssetRegister] A
WHERE A.LocationRoomID = AR.LocationRoomID
FOR XML PATH(''))), 1, 2,''))+')'
,LR.[RoomNo]
,COUNT(*)
FROM [dbo].[AssetRegister] AR
INNER JOIN [dbo].[LocationRoom] LR
on AR.LocationRoomID = LR.LocationRoomID
GROUP BY LR.[RoomNo],AR.LocationRoomID;
Result
DB<>Fiddle
SQLFiddle
Edit:
Thank you very much is it possible to get all the 19 rows each one
with their AssetBarcode 01780, Dell Computer, R001, 4
SELECT AR.AssetID,
AR.[Description],
LR.[RoomNo],
COUNT(*) OVER(PARTITION BY LR.RoomNo)
FROM [dbo].[AssetRegister] AR
INNER JOIN [dbo].[LocationRoom] LR
on AR.LocationRoomID = LR.LocationRoomID
Result
AssetID Description RoomNo (No column name)
01780 DELL LAPTOP R0001 4
01781 DELL MONITOR R0001 4
01782 DELL CPU R0001 4
01783 DELL KEYBOARD R0001 4
01784 HP LAPTOP R0002 4
01785 HP MONITR R0002 4
01786 HP CPU R0002 4
01787 HP KEYBOARD R0002 4
01788 APPLE LAPTOP AIR R0003 8
...*(19 rows)*
DB<>Fiddle