Selecting a Column from another table

  • I have a query which returns a column name. This column name has to be selected in another query.

    Assume a table A with column Col_Name having the value 'ColA'. This ColA is a column in another table B. I have to get the value of ColA from Table B.

    Can anyone suggest me a single SQL Query to achieve this?

  • Write the Coreleated Query to solve the this kinds of problem.

  • i think i cannot use a correlated sub query here bcoz the column name from Table B has to come from 'col_Name" column of Table A. I will not be aware of the column of Table B while writing the query.

  • With this, you're going to have to resort to dynamic SQL. Build up the statement as a string, then execute it. (sp_executesql)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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