sql Server 将数据库带有逗号的栏位分成多条记录

Posted on 2017-05-31 15:03  qhy1277  阅读(261)  评论(0编辑  收藏  举报

--临时表

WITH CMSHotelPIC AS (
SELECT [圖片代碼],[分類編號],CHARINDEX(',',[分類編號]) STA,CHARINDEX(',',[分類編號])-1 LENS FROM CMSHotelPIC20170519
UNION ALL
SELECT [圖片代碼],[分類編號],CHARINDEX(',',[分類編號],STA+1) STA,CHARINDEX(',',[分類編號],STA+1)-STA-1 LENS FROM CMSHotelPIC WHERE STA<>0)
--查询资料
SELECT [圖片代碼],SUBSTRING([分類編號],STA-LENS,LENS) FROM CMSHotelPIC
WHERE STA<>0

Copyright © 2024 qhy1277
Powered by .NET 9.0 on Kubernetes