Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Assign return of a query as a column name

Author  Topic 

lio1972
Starting Member

19 Posts

Posted - 2014-02-04 : 10:32:43
Is there a way to achieve that? I have a query with a subquery and I want to assign the return from the query as a column name in the subquery.

something like that where WorkDay is the return from the main query

as Convert(Varchar(10),WorkDay,110)
Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-02-22 : 11:50:16
You need to use dynamic SQL. But why do you want to do this?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-23 : 03:07:31
Sounds like attempt is for creating some kind of crosstab logic. If that is the case use PIVOT
see
http://beyondrelational.com/modules/2/blogs/70/posts/10840/dynamic-pivot-in-sql-server-2005.aspx
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -