SQL拆分字符串并放小写?

时间:2022-06-01 07:35:22

I have a User_Id column with data DOMAIN\USERID

我有一个带有数据DOMAIN \ USERID的User_Id列

I need it to be DOMAIN\userid

我需要它是DOMAIN \ userid

Whats the (sql server) sql?

什么是(sql server)sql?

Update: Answer from @David McEwing

更新:来自@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 个解决方案

#1


This should do the trick:

这应该做的伎俩:

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

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

#2


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


This should do the trick:

这应该做的伎俩:

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

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

#2


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