我想我的输出这就好比转换
BachNo|Release Qty
----------
A |10
A |30
A |40
B |90
B |30
我要转这个结构导入
BatchNO | Qty Release1 | Qty Release2 | Qty Release3
----------------------------------------------------
A | 10 | 30 | 40
B | 90 | 30 | Null
在第一输出端产生行数将是动态的,所以转置输出可以具有列的n个
见下文提到links
Efficiently convert rows to columns in sql server
如果仍然没有找到搜索对谷歌有各种technical sites
https://www.google.co.in/?gws_rd=ssl#q=Convert+Rows+Into+Columns+SQL+Server很多很多的例子
对于已知的列数其可能的,但对于列的动态数量不是很肯定。虽然你可以使用这样的事情后来又进一步分裂它在处理。
SELECT BatchNo , STUFF(( SELECT ','+ ReleaseQty FROM TableName a
WHERE b.BatchNo = a.BatchNo FOR XML PATH('')),1 ,1, '') Members
FROM TableName b
GROUP BY BatchNo;
这应该给你的东西等的输出:
BatchNo | ReleaseQty
-------- | ------------------------
A | 10,30,40
B | 90,30