sqlserver数据,将一行某一列字符串的值用“_”分割分别填充到这一行的其他列


分割字符到列
DECLARE @a VARCHAR(10)
SET @a ='00G-2-1102'
SELECT CHARINDEX('-',@a,CHARINDEX('-',@a))
SELECT CHARINDEX('-',@a,CHARINDEX('-',@a)+1)

SELECT SUBSTRING(@a,CHARINDEX('-',@a)+1,(CHARINDEX('-',@a,CHARINDEX('-',@a)+1) - CHARINDEX('-',@a,CHARINDEX('-',@a)))-1)

SELECT SUBSTRING(@a,CHARINDEX('-',@a,CHARINDEX('-',@a)+1)+1,LEN(@a)-CHARINDEX('-',@a,CHARINDEX('-',@a)+1))

 

//数据库的值

//building  某一列字符串 =00G-2-1102

UPDATE TABLE SET voice=SUBSTRING(building,CHARINDEX('-',building)+1,(CHARINDEX('-',building,CHARINDEX('-',building)+1) - CHARINDEX('-',building,CHARINDEX('-',building)))-1),
check_house=SUBSTRING(building,CHARINDEX('-',building,CHARINDEX('-',building)+1)+1,LEN(building)-CHARINDEX('-',building,CHARINDEX('-',building)+1))

posted @ 2019-11-12 13:31  枫岫  阅读(366)  评论(0编辑  收藏  举报