Sql server 2012 他们那你一开始就不会介绍了。 --like this I have 6000 usernames select * from tblUsers where Username in ('abc ','xyz ',' pqr ',' mnop ' );

Sql server 2012 他们那你一开始就不会介绍了。 --like this I have 6000 usernames select * from tblUsers where Username in ('abc ','xyz ',' pqr ',' mnop ' );,sql-server-2012,select,Sql Server 2012,Select,他们那你一开始就不会介绍了。 --like this I have 6000 usernames select * from tblUsers where Username in ('abc ','xyz ',' pqr ',' mnop ' ); select * from tblUsers where LTRIM(RTRIM(Username)) in (ltrim(rtrim('abc')),ltrim(rtrim('xyz')),ltrim(rtrim('pqr')),ltri

他们那你一开始就不会介绍了。
--like this I have 6000 usernames
select * from tblUsers where Username in ('abc  ','xyz  ',' pqr  ',' mnop  ' );
select * from tblUsers where LTRIM(RTRIM(Username)) in (ltrim(rtrim('abc')),ltrim(rtrim('xyz')),ltrim(rtrim('pqr')),ltrim(rtrim('mnop')));
select * 
from tblUsers
where RTRIM(LTRIM(Username)) in ('abc','xyz','pqr','mnop');
Answer: SELECT * FROM tblUsers WHERE LTRIM(RTRIM(Username)) in ('abc','xyz','pqr','mnop');
  select * from tblUsers where Username in ((select distinct 
  STUFF((SELECT distinct ', ' + RTRIM(LTRIM(t1.Username))
         from table2 t1
            FOR XML PATH(''), TYPE
            ).value('.', 'NVARCHAR(MAX)') 
        ,1,2,'') UserName
from table2 t) );
-- drop table dbo.tblUsers
create table dbo.tblUsers
(
    UserId INT NOT NULL IDENTITY(1, 1) CONSTRAINT PK_UserTest PRIMARY KEY,
    Username NVARCHAR(64) NOT NULL,
    UsernameTrimmed AS LTRIM(RTRIM(Username)) PERSISTED
)
GO

-- other columns may be included here with INCLUDE (col1, col2)
CREATE INDEX IDX_UserTest ON dbo.tblUsers (UsernameTrimmed)
GO

insert into dbo.tblUsers (Username) VALUES ('abc  '),('xyz  '),(' pqr  '), (' mnop  '), ('abc'), (' useradmin '), ('etc'), (' other user ')
GO 

-- some mock data to obtain a large number of records
insert into dbo.tblUsers (Username) 
select top 20000 SUBSTRING(text, 1, 64) from sys.messages 
GO
-- this will use the index (index seek)
select * from tblUsers where UsernameTrimmed in (LTRIM(RTRIM('abc')), LTRIM(RTRIM(' useradmin ')));
create table dbo.searchedUsers
(
    Username NVARCHAR(64) NOT NULL,
    UsernameTrimmed AS LTRIM(RTRIM(Username)) PERSISTED
)
GO
select U.* 
from tblUsers AS U 
   join dbo.searchedUsers AS S ON S.UsernameTrimmed = U.UsernameTrimmed 
create table a (a char(1))

insert into a values('a')
insert into a values('b')
insert into a values('c')
insert into a values('d')

create table #b (atmp char(5))

insert into #b values ('a  ')
insert into #b values (' b')
insert into #b values (' c  ')

select * from a where a in (select ltrim(rtrim(atmp)) from #b)
= CONCATENATE("'",TRIM(SUBSTITUTE(A1,"'","''")),"',")