select * 
from client a, product b 
where charindex(a.type ,b.ctype) > 0select * 
from client a, product b 
where b.ctype like '%' + a.type + '%'

解决方案 »

  1.   

    fun()不限
    只要能达到该功能即可如果sql server 2000 有数组的话倒是很好做没有数组还需要临时表,很麻烦想听听大家怎么做的。
      

  2.   

    CREATE FUNCTION aaa(@ctype tinyint)    
    RETURNS varchar(100)
    AS    
    Begin   
    declare @str varchar(100) 
    select @str=case @ctype when 1 then '1'
                                when 2 then '2'
    when 4 then '4'
    when 3 then '1,2'
    when 5 then '1,4'
    when 6 then '2,4'
    when 7 then '1,2,4' end
       return @str
       
    End    
      

  3.   

    create table client(type int, name varchar(10))
    insert into client values(1,'游客')
    insert into client values(2,'会员')
    insert into client values(4,'卖家')
    go
    create table product(ctype int, name varchar(30))
    insert into product values(1,'游客') 
    insert into product values(2,'会员') 
    insert into product values(4,'卖家') 
    insert into product values(3,'游客会员') 
    insert into product values(5,'游客卖家') 
    insert into product values(6,'会员卖家') 
    insert into product values(7,'游客会员卖家') 
    goselect distinct m.type , n.ctype , m.name , n.name
    from client m, product n
    where charindex(m.name ,n.name) > 0 drop table client , product/*
    type        ctype       name       name                           
    ----------- ----------- ---------- ------------------------------ 
    1           1           游客         游客
    1           3           游客         游客会员
    1           5           游客         游客卖家
    1           7           游客         游客会员卖家
    2           2           会员         会员
    2           3           会员         游客会员
    2           6           会员         会员卖家
    2           7           会员         游客会员卖家
    4           4           卖家         卖家
    4           5           卖家         游客卖家
    4           6           卖家         会员卖家
    4           7           卖家         游客会员卖家(所影响的行数为 12 行)*/
      

  4.   

    如果只有1\2\4的组合,用case when吧。
      

  5.   

    dawugui:
            兄弟,你这个好像不对吧?可能我表述不清晰,举例说如果produce表中为3,那得将client表中1和2的记录都显示;product表为5那得将client表中1和4显示。
      

  6.   

    sdhdy,libin_ftsafe :说得有道理!
      

  7.   

    dawugui:是我没看清楚,比较呆,你的算法真好啊!