如果输入参数为 1,‘’,1
  那么输出为: 
    1,'fdf1','namne1',12,1
    2,'fdf2','name2','24,1
    4,'fdf4','name4',12,1如果输入参数为 1,‘’,1
    2,'fdf2','name2','24,1谢谢
-----------------
有什麼不同?

解决方案 »

  1.   

    猜一個use Tempdb
    go
    --> --> 
     
    if not object_id('T1') is null
    drop table T1
    Go
    Create table T1([UID] int,[F1] nvarchar(4),[F2] nvarchar(4))
    Insert T1
    select 1,N'aad1',N'fdf1' union all
    select 2,N'aad2',N'fdf2' union all
    select 3,N'aad3',N'fdf3' union all
    select 4,N'aad4',N'fdf4'
    Go
    --> --> 
     
    if not object_id('T2') is null
    drop table T2
    Go
    Create table T2([UID] int,[name] nvarchar(6),[age] int,[gender] int)
    Insert T2
    select 1,N'namne1',12,1 union all
    select 2,N'name2',24,1 union all
    select 3,N'name3',36,1 union all
    select 4,N'name4',12,1 union all
    select 5,N'name5',24,1 union all
    select 6,N'name6',36,1
    Go--> --> 
     
    if not object_id('T3') is null
    drop table T3
    Go
    Create table T3([UID] int,[UIDSET] nvarchar(3))
    Insert T3
    select 1,N'2,4' union all
    select 2,''
    Go
    Select 
    T2.name,T2.age,T2.gender,T1.UID,T1.F2
     from T1
    inner join T2 on t1.UID=t2.UID
    where
    exists(select 1 from T3 where [UID]=t2.[UID] or ','+[UIDSET]+',' like '%,'+rtrim(t2.[UID])+',%')
    and T2.gender=@gender