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.
| Author |
Topic |
|
SqlStar
Posting Yak Master
121 Posts |
Posted - 2003-09-05 : 03:45:55
|
| Hi,Select Col1 as 'TestCol' From Table1Its working fine.but I want like this:Declare @a varchar(10)Set @a = 'TempCol'Select Col1 as @a From Table1Its given error. How I can achive this?Send me ur valuable reply ASAP.Thanks":-) IT Knowledge is power :-)" |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2003-09-05 : 04:05:17
|
The name of your output is really a presentation issue and should be handled by your front end app. If you really want to do this in sql, you will need to use dynamic SQL to achieve what you want.declare @thing varchar(10)declare @thing2 nvarchar(60)set @thing = 'cool'set @thing2 = 'select top 1 col1 as ' + @thing + ' from table1'select @thing2exec sp_executesql @thing2 -------Moo. :) |
 |
|
|
SqlStar
Posting Yak Master
121 Posts |
Posted - 2003-09-05 : 05:34:26
|
| Thanks for your immediate response.Is there any way to get the same result without using DYNAMIC SQL?If any solution comes without using dynamic sql,that should be more useful to me.otherwise, i will use dynamic sql only.Thanks":-) IT Knowledge is power :-)" |
 |
|
|
Amethystium
Aged Yak Warrior
701 Posts |
Posted - 2003-09-05 : 06:22:24
|
| There is no other way to do it apart from Dynamic SQL.------------------------------------------------------------------------------I enjoy using SQL Server but I am not part of the Microsoft fanboy club! NEVER!! |
 |
|
|
|
|
|