SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Assign return of a query as a column name
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

lio1972
Starting Member

19 Posts

Posted - 02/04/2014 :  10:32:43  Show Profile  Reply with Quote
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

Edited by - lio1972 on 02/04/2014 10:36:16

madhivanan
Premature Yak Congratulator

India
22769 Posts

Posted - 02/22/2014 :  11:50:16  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

India
52325 Posts

Posted - 02/23/2014 :  03:07:31  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000