Created
October 18, 2019 00:52
-
-
Save megatontech/9bbb10674b68e2d1ed7c88cd6f78e7b9 to your computer and use it in GitHub Desktop.
SQLSERVER拼接字符串
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT DISTINCT | |
OrderID, | |
supplier = STUFF( | |
( | |
SELECT DISTINCT | |
',' + Supplier | |
FROM | |
Ord_Order_Cost t | |
WHERE | |
OrderID = t1.OrderID | |
AND ItemType = 0 | |
AND CostType = 2 | |
GROUP BY | |
',' + Supplier FOR XML PATH ('') | |
), | |
1, | |
1, | |
'' | |
), | |
SupplierIds = STUFF( | |
( | |
SELECT DISTINCT | |
',' + CONVERT (NVARCHAR(50), SupplierID) | |
FROM | |
Ord_Order_Cost t | |
WHERE | |
OrderID = t1.OrderID | |
AND ItemType = 0 | |
AND CostType = 2 | |
GROUP BY | |
',' + CONVERT (NVARCHAR(50), SupplierID) FOR XML PATH ('') | |
), | |
1, | |
1, | |
'' | |
) | |
FROM | |
Ord_Order_Cost t1 | |
GROUP BY | |
t1.OrderID, | |
supplier, | |
SupplierID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment