Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Posts
    162

    Unanswered: different column depending on other columns

    need help with get data from correct column depending on the data in other columns

    The table looks like this
    type1, name1, type2, name2, type3, name3

    type* column is INT and name* column is varchar

    for ex:
    if column type1 = 1 and column type2 = 1 and column type3 = 3 then result should be from column name1
    if column type1 = 2 and column type2 = 1 and column type3 = 2 then result should be from column name3
    and so on with various code.
    I have try "case" in many different ways but i just cant get it to work the way i want it.


    Thx in advance for any help

  2. #2
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    Try
    Code:
    SELECT CASE 
         WHEN type1 = 1 and type2 = 1 and column type3 = 3 
              then name1
         WHEN type1 = 2 and type2 = 1 and type3 = 2 
              then name3
    FROM MyTable
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  3. #3
    Join Date
    Mar 2004
    Posts
    162
    works like charm.

    thx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •