RE: [SQLQueriesNoCode] Can a variable be used to set a column alias?
- The only thing I can think of is a dynamically-created SQL statement. Be aware that this approach can introduce security vulnerabilities. I'm not sure about other platforms, but this is how you would do it in SQL Server:DECLARE @MyTitle varchar(20)SET @MyTitle = '[My Builders]'EXECUTE 'SELECT Builder_Name AS ' + @MyTitle + ' FROM Tbl_builders'-----Original Message-----I would like to customize a column header by specifying an alias in
From: gonforward [mailto:gonforward@...]
Sent: Sunday, November 30, 2003 10:42 PM
Subject: [SQLQueriesNoCode] Can a variable be used to set a column alias?
a "Select" statement using a variable instead of literal. My Select
statements error every time I try to use a variable but work fine
using a literal...
For example, using a literal everything works:
Select Builder_Name as [My Builders] from Tbl_builders
Fox and Jacobs
Using a declared variable to the same value it errors:
Declare @mytitle char (11)
set @mytitle = 'My Builders'
Select Builder_Name as @mytitle from Tbl_builders
Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near '@mytitle'.
I have tried many variations of the statement above and searched for
an internet example in vain. I would be grateful for a solution
using a variable!!
To unsubscribe from this group, send an email to:
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.