分割字符到列
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))