Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Identifying the column match from an in clause

$
0
0

Greetings all,

I have a dynamic query which populates a pseudo lookup table. It can (currently) populated anywhere from 1 to 8 columns, with an associated description.

Joining to the results of this query I have a table containing a list of accounts. These accounts have two identifiers I can use to join the appropriate row in my dynamically fed lookup table. The first of these identifiers always appears in one column, but the second can match any of the other columns.

the join looks like this:

inner join lookup
on PLID = PLID
and CV in (level0,level1,level2,level3...)

Not only would I like to clean up this join, but I also need to know which of the columns CV has matched too.

My first through was a case statement, but that would require me to know how many columns the dynamic table has, and adjust the query to reflect that each time.

case
    when cv = level1 then 1
    when cv = level2 then 2
...
end

So, my question is, does anyone have a nifty trick to solve either, or both of these problems?

Many thanks in advance.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>