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 |
|
neil_akoga
Yak Posting Veteran
56 Posts |
Posted - 2011-06-13 : 11:12:31
|
| ok, i've done this before but i can't think of how i did it last time. i have 4 tables as illustrated below. what i want to do is create the desired results table shown at the bottom. sorry if this isn't that complicated but i'm having a total brainfart todayprodtableitemcode / cat1 / cat2 / cat3123 / 1 / 2 / 3124 / 1 / 2 / 125 / 1 / 3 /126 / 1 / /cat1tablecat1 / cat1name1 / meatcat2tablecat2 / cat2name2 / steaks3 / burgerscat3tablecat3 / cat3name3 / sirloindesired results tableitemcode / cat1name / cat2name / cat3name123 / meat / steaks / sirloin124 / meat / steaks / 125 / meat / burgers / 126 / meat / / |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-13 : 12:55:47
|
| select t.itemcode, t1.cat1name, t2.cat2name, t3.cat3namefrom prodtable tleft join cat1table t1on t.cat1 = t1.cat1left join cat2table t2on t.cat2 = t2.cat2left join cat3table t3on t.cat3 = t1.cat3order by t.itemcodeWhy have 3 cat tables?==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|