0
A
回答
2
使用stuff()
with select ... for xml path ('')
method of string concatenation。
create table t (ProductId int);
insert into t values (68) ,(74) ,(58) ,(64) ,(67);
select
ProductIds = stuff((
select ','+convert(varchar(10),ProductId)
from t
for xml path (''), type).value('.','nvarchar(max)')
,1,1,'')
rextester演示:http://rextester.com/RZQF31435
回報:
+----------------+
| ProductIds |
+----------------+
| 68,74,58,64,67 |
+----------------+
+0
在DVD上看着侵略者Zim ......很多人大叫。 –
+0
@JohnCappelletti我通過保留我的sql小寫來平衡它^^^ – SqlZim
1
您可以使用串聯和選擇數據的東西,XML路徑從第一個逗號後..
select distinct stuff((select ',' + convert(char(2), productid) from #yourproductid for xml path('')),1,1, '')
from #yourproductid
你表:
create table #yourproductid(productid int)
insert into #yourproductid (productid) values (68),(74),(58),(64),(67)
相關問題
- 1. 將逗號分隔字符串轉換爲SQL Server中的bigint
- 2. 將由逗號分隔的數字字符串轉換爲列表<int>?
- 3. sql將列值轉換爲逗號分隔字符串
- 4. JavaScript將字符串轉換爲文字逗號列表
- 5. 在SQL中將字符串列表轉換爲Int列表
- 6. 將列表<int>轉換爲逗號分隔值的字符串
- 7. 將逗號分隔的字符串轉換爲int列表並驗證
- 8. 將逗號分隔的字符串轉換爲int PHP?
- 9. 轉換逗號分隔字符串INT爲int在PHP
- 10. 將逗號分隔的字符串轉換爲變量列表?
- 11. 將逗號分隔的雙字符串轉換爲列表
- 12. 將逗號分隔的字符串轉換爲列表
- 13. 將字符串轉換爲int,int轉換爲字符串
- 14. 將int轉換爲字符串sql
- 15. SQL - 將結果轉換爲逗號分隔的字符串
- 16. 轉換列表爲雙引號逗號分隔字符串
- 17. 我如何轉換逗號分隔字符串轉換成列表<int>
- 18. 將字符串轉換爲int陣列
- 19. 將字符串[]轉換爲逗號分隔的字符串。
- 20. 矢量將字符串轉換爲逗號字符串?
- 21. 將逗號分隔字符串轉換爲多個字符串
- 22. SQL Server將字符串轉換爲datetime
- 23. 使用sql查詢將字符串轉換爲int
- 24. 將signed int轉換爲SQL Server中的字符串ip地址
- 25. 用逗號將字符串轉換爲double和int是不同的。爲什麼?
- 26. 如何將NVARCHAR逗號分隔列表轉換爲INT?
- 27. 在逗號轉換終止字符串爲int
- 28. SQLite將列轉換爲逗號分隔字符串
- 29. 將int字符串的列表/元組轉換爲int
- 30. 將逗號分隔的字符串轉換爲SP中的sql表格
Google:「sql server aggregate string concat」 –