November 12, 2007 at 11:36 pm
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?
November 12, 2007 at 11:50 pm
Write the Coreleated Query to solve the this kinds of problem.
November 13, 2007 at 12:03 am
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.
November 13, 2007 at 1:31 am
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
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply