2015-08-28 64 views
-3
stuff((select distinct ',',Convert(varchar(256),y.RoomPlanID) 
from(
    select x.RoomPlanID ,x.RoomPlanHierarchy from (select utblConfigDestRoomRates.RoomPlanID,utblMstRoomPlans.RoomPlanHierarchy 
          FROM utblConfigDestRoomRates inner 
          JOIN utblMstRoomPlans on utblConfigDestRoomRates.RoomPlanID=utblMstRoomPlans.RoomPlanId 
          WHERE PropertyTypeID=1 
          AND BusinessID='AAAA' 
          AND('25-Aug-2015' BETWEEN DateEffective AND DateEnd) 
          AND StarRank=3  group by RoomPlanHierarchy order by RoomPlanHierarchy asc 
          ) x 
          --order by 
          -- x.RoomPlanHierarchy 
          )y 
          FOR XML PATH('')), 1, 1, '') 
+0

你的意思是ms sql server,對嗎?它被標記爲mysql。沒有什麼比一個標題繼續。 – Drew

+0

嘗試在'for xml'子句之前的'y'之後移動順序。 –

+0

問題制定得很差 – Allie

回答

0

您可以使用ROW_NUMBER(Transact-SQL)函數。我認爲這樣的訂單x.RoomPlanHierarchy像這樣

stuff((select distinct ',',Convert(varchar(256),y.RoomPlanID) 
from(
    select x.RoomPlanID ,x.RoomPlanHierarchy,ROW_NUMBER() OVER(ORDER BY x.RoomPlanHierarchy asc) AS Row from (select utblConfigDestRoomRates.RoomPlanID,utblMstRoomPlans.RoomPlanHierarchy 
          FROM utblConfigDestRoomRates inner 
          JOIN utblMstRoomPlans on utblConfigDestRoomRates.RoomPlanID=utblMstRoomPlans.RoomPlanId 
          WHERE PropertyTypeID=1 
          AND BusinessID='AAAA' 
          AND('25-Aug-2015' BETWEEN DateEffective AND DateEnd) 
          AND StarRank=3  group by RoomPlanHierarchy 
          ) x 
          --order by 
          -- x.RoomPlanHierarchy 
          )y 
          FOR XML PATH('')), 1, 1, '') 
+0

列'utblConfigDestRoomRates.RoomPlanID'在選擇列表中無效,因爲它不包含在聚合函數或GROUP BY子句中。 – user3213752

相關問題