get lookup data

  • Hello,

    I am also news in this field...

  • However the columns are named, you can use the query from the first structure to discern the query for your actual table structure. Also, don't discount Jeff's post about looking it up. Having the answer is one thing, but understanding it is another. You shouldn't just run code you're given unless you understand it and test it yourself.

    Joins are fundamental to SQL and understanding them is pretty critical if you want to continue to work in it. What Jeff was doing it showing you where to look to get the answer. Knowing how to read MSDN is an important part of working in SQL Server.

  • Ed Wagner (6/7/2013)


    However the columns are named, you can use the query from the first structure to discern the query for your actual table structure. Also, don't discount Jeff's post about looking it up. Having the answer is one thing, but understanding it is another. You shouldn't just run code you're given unless you understand it and test it yourself.

    Joins are fundamental to SQL and understanding them is pretty critical if you want to continue to work in it. What Jeff was doing it showing you where to look to get the answer. Knowing how to read MSDN is an important part of working in SQL Server.

    Spot on, Ed. Thanks for the support.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Try this code

    declare @table1 TABLE

    (

    col1 int,

    col2 char(2),

    col3 char(2)

    )

    insert into @table1 values(1,'_A','11')

    insert into @table1 values(2,'_B','12')

    insert into @table1 values(3,'_C','12')

    insert into @table1 values(4,'_A','11')

    declare @table2 TABLE

    (

    id char(2),

    val char(2)

    )

    insert into @table2 values('_A','A')

    insert into @table2 values('_B','B')

    insert into @table2 values('_C','C')

    insert into @table2 values('11','AA')

    insert into @table2 values('12','BB')

    insert into @table2 values('13','CC')

    select t1.col1,t1.col2,t2.val from @table1 t1 INNER JOIN @table2 t2

    ON t1.col3=t2.id

    OUTPUT:

    col1 col2 val

    ----------- ---- ----

    1 _A AA

    2 _B BB

    3 _C BB

    4 _A AA

  • Thank you

Viewing 5 posts - 16 through 19 (of 19 total)

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