Is this query posible in Sql Server 2005 ?

  • Select Table.Name as Name,

    (Select units from ¿Table.Name? where (¿Table.Name?.Id = Table.Id)) as Units

    from Table

    where id = 2

    The Idea is to use the value of Table.Name in the second Select , depending de tablename stored in the Table.Name.

    Tnks in advance

  • Only with dynamic SQL.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • In my case , i need to create a view , do you think is not posible ?

    Tks.

  • It is possible in a view if you create a column called "TableName". Look at how they do it with the Information_Schema views... particularly the Information_Schema.Columns view.

    --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)

Viewing 4 posts - 1 through 4 (of 4 total)

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