Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-09-25 : 02:34:33
|
Table1ID Code1 A2 B3 C4 D5 E6 F12 L13 M14 N15 O16 P17 Q18 RTable2VALUE1,2,42,5,63,44,6,112,16,118,12,1I have two tables as above and want result as under:VALUE_CodeA,B,DB,E,FC,DD,F,AL,P,AR,L,APlease advice!Pushp |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-09-25 : 02:50:09
|
using fnParseList from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033with 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[spoiler]Time is always against us[/spoiler] |
|
|
|
|
|
|
|