February 14, 2002 at 3:47 pm
I have a sp that returns a column for each month of the most recent quarter. Is there a way to return the month name as the column name?
February 14, 2002 at 5:12 pm
You could do it dynamically by building a the SQL string in a variable object concatinating the names in the way you want and then executing the variable.
Ex.
DECLARE @SQLStr AS VARCHAR(500)
SET @SQLStr = 'SELECT col1 AS ' + WHATEVERTOGETTHEMONTHNAME + ' FROM tblX'
EXE(@SQLStr)
However, you break the ownership chain and may have to give SELECT rights to the underlying table itself. Let me know if you need a better example.
February 15, 2002 at 3:27 pm
cool,
I can get it to work using
execute sp_executesql @stmt
is that what you mean?
is that the most efficient way?
February 15, 2002 at 3:42 pm
February 15, 2002 at 5:37 pm
And you do have to have the ()'s around your variable.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply