我现在有以下两个表:
TABLE1:XQID       CID
--------------------
0         00001,00002,00005 
1         00002
2         00002,00005TABLE2:CID       CNAME
---------------------
00001     ADGR
00002     BDTQW
00005     EBDEER我想得到如下结果该怎样写 SQL 语句啊:
XQID       CNAME
-----------------------
0          ADGR
0          BDTQW
0          EBDEER
1          BDTQW
2          BDTQW
2          EBDEER2
2

解决方案 »

  1.   

    select t1.xqid,t2.Cname from table1 t1,table1 t2 where charindex(','+t2.CID+',',','+t1.Cid+',')>0
      

  2.   

    楼上可能笔误了!
    select t1.xqid,t2.cname from table1 t1,table2 t2 where charindex(','+t2.CID+',',','+t1.Cid+',')>0
    order by 1
      

  3.   

    select t1.xqid,t2.cname from table1 t1,table2 t2 where charindex(','+t2.CID+',',','+t1.Cid+',')>0
    order by xqid
    charindex的用法