当前位置: 代码迷 >> Sql Server >> 分隔字符,选定需要的行
  详细解决方案

分隔字符,选定需要的行

热度:28   发布时间:2016-04-27 12:02:41.0
分隔字符,选出需要的行
SQL code
create table temp_T1(   ID int,   U1 varchar(100),   U2 varchar(100)   )insert into temp_T1 select 1,'AA2,BB3,AA,AA4',''insert into temp_T1 select 2,'DD1,DD2',''insert into temp_T1 select 3,'CC1',''insert into temp_T1 select 4,'EE8,AA',''insert into temp_T1 select 5,'XX',''insert into temp_T1 select 6,'','TT'insert into temp_T1 select 7,'CCCC',''insert into temp_T1 select 8,'','AA'insert into temp_T1 select 9,'BXXX',''select * from temp_T1ID          U1                                                                                                   U2----------- ---------------------------------------------------------------- ----------------------------------------------------------------1           AA2,BB3,AA,AA4                                                                                       2           DD1,DD2                                                                                              3           CC1                                                                                                  4           EE8,AA                                                                                               5           XX                                                                                                   6                                                                                                                TT7           CCCC                                                                                                 8                                                                                                                AA9           BXXX                                                                                                 (9 行受影响)


---------------------------------------------
找出U1栏中有AA的或者U2栏中没有AA的行。请问如何写这个SQL语句比较好呢?



------解决方案--------------------
','+U1+',' LIKE '%,AA,%'
------解决方案--------------------
SQL code
--漏写分隔符select *from tbwhere ','+u1+',' like '%,AA,%' or ','+u2+',' not like '%,AA,%'
  相关解决方案