SQL Server Performance

Dynamic SQL

Discussion in 'SQL Server 2008 General Developer Questions' started by rahul_koduru, Apr 5, 2010.

  1. rahul_koduru New Member

    Hi,
    I have the following tables.

    CREATE TABLE LOOKUP (
    KEY CHAR(2)
    ,COL1 CHAR(1)
    )

    INSERT INTO LOOKUP VALUES
    ('00','A'),('01','B'),('10','C'),('11','D')

    CREATE TABLE DATA (
    KEY CHAR(2)
    ,A INT
    ,B INT
    ,C INT
    ,D INT
    )

    INSERT INTO T2 VALUES
    ('00',1,2,3,4),('01',5,6,7,8)

    Ihave to lookup each key from DATA table in the LOOKUP table and pickColumns A,B,C or D according to it to get my actual data. Somebodysuggested I could do this using Dynamic SQL. Any help would beappreciated.

    Thanks.
  2. Adriaan New Member

    Suggestion #1 - use joins.
    Suggestion #2 - use CASE expressions.
    Either suggestion might work. Work it out by yourself, using Books Online as main reference, so you'll learn from this.
  3. hajan New Member

    Hello there...
    Well, I'm not sure if I understand well so thats why I'm going to ask what is the exact relationship between these two tables?
    Yes, you may use joins or case expressions or even subqueries to achieve your requirement, but knowing relationship would help us provide better solution.
    Thanks,
    Hajan

Share This Page