| 发表于:2007-04-20 16:59:103楼 得分:0 |
--建立測試環境 create table tablea (customnerid char(4), productlist nvarchar(100)) insert tablea select '1000 ', '200 ' union all select '1001 ', '201,202 ' union all select '1002 ', '200,202 ' create table tableb (productid char(3), description nvarchar(100)) insert tableb select '200 ', 'description0 ' union all select '201 ', 'description1 ' union all select '202 ', 'description2 ' union all select '203 ', 'description3 ' union all select '204 ', 'description4 ' go --測試 --方法一: select a.customnerid, b.productid, b.[description] from tablea a inner join tableb b on charindex(b.productid, a.productlist) > 0 --方法二: select a.customnerid, b.productid, b.[description] from tablea a inner join tableb b on a.productlist like '% ' + b.productid + '% ' go --刪除測試環境 drop table tablea, tableb go --結果 /* customnerid productid description 1000 200 description0 1001 201 description1 1001 202 description2 1002 200 description0 1002 202 description2 */ | | |
|