question

rohitk avatar image
rohitk asked

case with join

Hi Everyone,

I am have a big table with some column having lookup values. I want to create a description column for each lookup column and populate with description from lookup table.

here is one example

--main table

select id1, id2, id3 from idtable;

id1 id2 id3

1 2 3

1 3 4

--look up table

select code , id, desc from lookup;

code id desc

id1 1 id1-desc1

id2 2 id2-desc2

id2 3 id2-desc3

id3 3 id3-desc3

id3 4 id3-desc4


I want the result set like:

id1 id1desc id2 id2desc id3 id3desc

1 id1-desc1 2 id2-desc2 3 id3-desc3

1 id1-desc1 3 id2-desc3 4 id3-desc4


what is the best and most eficient way to write the sql solution for this?


Thanks,

Ro


sqlserver2012sql2014
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.