Get ID from look up table based on value passed to function

  • Hi,

    I have a requirement regarding a color combination data. I have a lookup table that holds a colorid, p1, p2, p3, p4 to p8 which will be having colors Red, Green and Amber. P1 to P8 columns holds these three colors based on their combinations.

    I have attached the look up table data for reference.

    I need to pass the color values to p1 to p8 and need to retrieve the color id based on the passed color.

    If we pass values for all p1 to p8 then it is easy to get the color code, however it will not happen. The passed values may be dynamic. ie we will not have all 8 values all the times. sometimes we will have 2 colors passed, sometimes 5 colors will be passed.

    If i pass only two colors say red and red, i need the color id of only the row that has red and red for p1 and p2 alone. i dont want want all the colorid's that has red and red in p1 and p2 and some other colors in p3 to p4.

    The exact colorid of the combination must be returned on passing the values to p1 and p2.

    To elaborate; I am passing Red and Red as values to P1 and P2. In the look up table we can have 10 rows that has red and red i p1 and p2 like

    colorid p1p2p3p4p5p6p7p8

    1 redred

    10 redredred

    20 redredred

    30 redredredred

    40 redredredredred

    50 redredredredredred

    60 redredredredredredred

    70 redredredredredredredred

    So the result must have only the colorid 1 and not all the colorid's listed above. when I pass 3 red as values for p1, p2, p3 then the result must be 10. Colorid 1, 20, 30, 40, 50, 60 and 70 must not come in the result.

    I need a function or procedure that will accept the arguments and provide me the result based on the values.

    Can anyone help me with this?

  • I would add a computed persisted indexed column that holds the "summary" of all values, preferred in a shorter form, e.g. just the first character (either based on the value itself or on a lookup table).

    In your case:

    colorid p1 p2 p3 p4 p5 p6 p7 p8....combined

    1 red red..................................rr

    10 red red red...........................rrr

    20 red red red...........................rrr

    30 red red red red......................rrrr

    40 red red red red red

    50 red red red red red red

    60 red red red red red red red

    70 red red red red red red red red

    An empty value would be represented by a blank character.

    To query the data just build a search string based on the first character of each parameter or based on the lookup table.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Hi Lutz,

    Thanks a lot for your idea. I will create a computed column using my first character of my value.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply