select (case when charindex(',',TP)>0 then left(TP,charindex(',',TP)-1) else TP end) from table1

解决方案 »

  1.   

    select * from table2 where exists(select 1 from table1 where ','+tp+',' like '%,'+cast(table2.tp as varchar(10))+',%')
      

  2.   

    如果是要join:select * from table2,table1 where ','+table1.tp+',' like '%,'+cast(table2.tp as varchar(10))+',%'
      

  3.   


    select (
         case TP when charindex(',',TP) =0 then TP else
                  substring(TP,1,charindex(',',TP)-1))
      

  4.   

    select left(TP+',',charindex(',',TP+',')-1) from table1
      

  5.   

    select (case when charindex(',',TP)>0 then left(TP,charindex(',',TP)-1) else TP end) from table1查询table2:
    select * from table2 where TP in 
    (
    select (case when charindex(',',TP)>0 then left(TP,charindex(',',TP)-1) else TP end) from table1
    )
      

  6.   


    select * from table1 a,table2 b
    where case when charindex(',',a.tp)>0 then left(a.tp,charindex(',',a.tp)-1) else a.tp end=b.tp
      

  7.   

    select left(TP+',',charindex(',',TP+',')-1) from table1
    在字段的最后加一个逗号再取逗号前面的字符串就没必要用  case when 了