SELECT h.ID,h.RoomID,h.HotelID,h.RoomTypeID,h.RoomTypeName,o.ID,OccupancyID,
o.TeamName,t.DRoom_Price,t.TRoom_Price,t.TRoom_OverTime,ROW_NUMBER() over(order by Occupancyid) as rowno,
RoomNum = STUFF((SELECT ',' + CAST(RoomNum AS NVARCHAR(MAX))
FROM StayHistory WHERE (Occupancyid = h.Occupancyid)
FOR XML PATH ('')),1,1,'')
from StayHistory h,Occupancy o,RoomType t
where h.OccupancyID=o.ID And h.RoomTypeID=t.ID And h.IsCheckOut=0
group by o.ID,h.ID,h.RoomID,h.HotelID,h.RoomTypeID,h.RoomTypeName,OccupancyID,
o.TeamName,t.DRoom_Price,t.TRoom_Price,t.TRoom_OverTime