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))

上一篇:重置sqlserver自增长列的种子


下一篇:sqlServer数据库常用连接字符串