-2
我似乎無法弄清楚爲什麼這不會在MS SQL Server中工作。它似乎不分組線。具體來說,我看到:什麼是錯誤的這對於XML路徑
1036 SC
1036 S1
1094 VO
1094 V1
1094 V2
當我希望看到:
1036 SC ,S1
1094 VO,V1,V2
有人可以看到語法錯誤嗎?
SELECT DISTINCT oa.acct_cd AS [Account],
STUFF((SELECT ',' + CASE WHEN o.trans_type like 'BUY%' then 'buy of ' else 'sell of ' end + s.ticker AS [text()]
FROM [dbo].[synCRtblTS_ORDER] o INNER JOIN [dbo].[synCRtblCSM_SECURITY] s
ON o.SEC_ID = s.SEC_ID
WHERE o.ORDER_ID = oa.ORDER_ID AND o.status IN ('OPEN','WORK','PENDING')
FOR XML PATH('')), 1, 1, '') [buy/sell]
FROM [dbo].[synCRtblTS_ORDER_ALLOC] oa INNER JOIN tblPortfolio p
ON oa.ACCT_CD = p.Account INNER JOIN tblInvestmentObjective io
ON io.Code = p.InvestmentObjective
WHERE p.AsOfDate = (SELECT AsOfDate FROM tblDateAsOf) and io.CashMgmtStrategy IN ('SC','VO')
GROUP BY oa.ORDER_ID, oa.acct_cd
order by 1
哪個dbms? (某些產品特定的SQL在那裏...) – jarlh
也許從GROUP BY中刪除oa.ORDER_ID? – jarlh
您能否比*「不起作用」更具體* *,您是否遇到錯誤?如果是這樣,則發佈錯誤消息。你有意想不到的結果嗎?如果是這樣,請發佈一些樣本數據,結果以及您期望的結果。就目前來看,這個問題只是一種閱讀而不是調試的練習! – GarethD