SQL拆分字符串并放小写?

时间:2009-07-08 02:13:00

标签: tsql

我有一个包含数据DOMAIN \ USERID

的User_Id列

我需要它是DOMAIN \ userid

什么是(sql server)sql?

更新 来自@David McEwing的回答

update UserTable 
set [User_Id] = SUBSTRING( [User_Id], 0, CHARINDEX('\',  [User_Id])+1) 
        + lower(SUBSTRING( [User_Id], CHARINDEX('\',  [User_Id])+1, len( [User_Id])))

2 个答案:

答案 0 :(得分:4)

SELECT LEFT(User_Id, CHARINDEX('\', User_Id)) -- grabs DOMAIN and '\'
+ LOWER(RIGHT(User_Id, 
      LEN(User_Id) - CHARINDEX('\', User_Id))) -- concat with lower of userid
FROM MyTable

答案 1 :(得分:2)

这应该可以解决问题:

declare @name varchar(50)
set @name= 'DOMAIN\USERID'

select SUBSTRING(@name, 0, CHARINDEX('\', @name)+1) 
        + lower(SUBSTRING(@name, CHARINDEX('\', @name)+1, len(@name)))