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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to set dynamic caption for columns

Author  Topic 

hdv212
Posting Yak Master

140 Posts

Posted - 2010-04-08 : 05:32:55
Hi
in my query, i need set deynamic caption for my column, something like this :

select actionName as actionName+'-'+actionID from actions

but apparently the 'as' keyword does not support this feature.
can anybody have an idea to accomplish this ?
thanks in advance

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-08 : 05:49:46
How should this work if a select returns many different actionID's and you can have only one caption?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-04-08 : 05:50:01
If there are more than one row then what will be caption for your column name ?

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-08 : 05:53:18
quote:
Originally posted by hdv212

Hi
in my query, i need set deynamic caption for my column, something like this :

select actionName as actionName+'-'+actionID from actions

but apparently the 'as' keyword does not support this feature.
can anybody have an idea to accomplish this ?
thanks in advance


Why do you want to do this?

Madhivanan

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

tishri
Yak Posting Veteran

95 Posts

Posted - 2010-04-08 : 07:54:19
DECLARE @sqlCommand varchar(1000)

SET @sqlCommand = 'select actionName as actionName' + '-' + actionID + ' from actions'
EXEC (@sqlCommand)

TCC
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-08 : 08:42:55
quote:
Originally posted by tishri

DECLARE @sqlCommand varchar(1000)

SET @sqlCommand = 'select actionName as actionName' + '-' + actionID + ' from actions'
EXEC (@sqlCommand)

TCC


Have you tried executing this?

Madhivanan

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

hdv212
Posting Yak Master

140 Posts

Posted - 2010-04-08 : 11:06:01
Thanks everybody
my query in my fisrt post is just an example and is not my real query!
this query does not works :

DECLARE @sqlCommand varchar(1000)
SET @sqlCommand = 'select actionName as actionName' + '-' + actionID + ' from actions'
EXEC (@sqlCommand)

i got this error :

Msg 207, Level 16, State 1, Line 2
Invalid column name 'actionID'.
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-04-09 : 03:34:53
quote:
Originally posted by hdv212

Thanks everybody
my query in my fisrt post is just an example and is not my real query!
this query does not works :

DECLARE @sqlCommand varchar(1000)
SET @sqlCommand = 'select actionName as actionName' + '-' + actionID + ' from actions'
EXEC (@sqlCommand)

i got this error :

Msg 207, Level 16, State 1, Line 2
Invalid column name 'actionID'.



Can you please tell us why you want to do this....???
As dynamic caption sounds logical
but multiple cation for single column
logically its not possible to even think
what you want to do i am not getting


Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

hdv212
Posting Yak Master

140 Posts

Posted - 2010-04-09 : 07:30:33
Sure.
i want to use dynamic caption in pivot table (cross-tab queries) which you can find here :
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=142412
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-09 : 08:18:27

This is for Dynamic PIVOT
http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx


Madhivanan

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

- Advertisement -