| Author |
Topic  |
|
|
pushp82
Yak Posting Veteran
67 Posts |
Posted - 09/25/2012 : 02:34:33
|
Table1 ID Code 1 A 2 B 3 C 4 D 5 E 6 F 12 L 13 M 14 N 15 O 16 P 17 Q 18 R
Table2 VALUE 1,2,4 2,5,6 3,4 4,6,1 12,16,1 18,12,1
I have two tables as above and want result as under: VALUE_Code A,B,D B,E,F C,D D,F,A L,P,A R,L,A
Please advice! Pushp |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16746 Posts |
Posted - 09/25/2012 : 02:50:09
|
using fnParseList from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033
with cte as
(
select t2.VALUE, csv.RowID, csv.Data, t1.Code
from Table2 t2
cross apply dbo.fnParseList(',', VALUE) csv
inner join Table1 t1 on csv.Data = t1.ID
)
select distinct stuff(CodeCSV, 1, 1, '')
from cte c
cross apply
(
select ',' + Code
from cte x
where x.VALUE = c.VALUE
order by RowID
for xml path ('')
) csv (CodeCSV)
KH Time is always against us
|
 |
|
| |
Topic  |
|
|
|