Nov 8, 2000 #1 Bamboosch Programmer Jun 23, 2000 6 DE Hi there, i think, it´s a very simple problem. how can i set an alias of a column by a variable ??? this will not work: DECLARE @pID int SET @pID=1015 SELECT customer AS @pID FROM ... is there a way ? thanks ;-) bamboosch
Hi there, i think, it´s a very simple problem. how can i set an alias of a column by a variable ??? this will not work: DECLARE @pID int SET @pID=1015 SELECT customer AS @pID FROM ... is there a way ? thanks ;-) bamboosch
Nov 8, 2000 #2 foxdev Programmer Feb 11, 2000 1,995 US As far as I can tell, column names or other identifiers cannot start with a letter; they must start with a letter or the underscore. Robert Bradley http://www.foxdev.com/ Upvote 0 Downvote
As far as I can tell, column names or other identifiers cannot start with a letter; they must start with a letter or the underscore. Robert Bradley http://www.foxdev.com/
Nov 8, 2000 #3 TomSark MIS Oct 19, 2000 448 US Simply get rid of the @ in the alias name... Tom Upvote 0 Downvote
Nov 8, 2000 Thread starter #4 Bamboosch Programmer Jun 23, 2000 6 DE it don´t work without the @, i need the content not the name of the variable... and it´s the same with letters instead of numbers... cst Upvote 0 Downvote
it don´t work without the @, i need the content not the name of the variable... and it´s the same with letters instead of numbers... cst
Nov 8, 2000 #5 TomSark MIS Oct 19, 2000 448 US Ahhh.. sorry, I misunderstood the quesiton... You could use execute to build the select string and execute the string as in: USE PUBS GO DECLARE @sql_str varchar(255) SET @pID='A015' -- cant start with a number, so I made it start with a char. Set @sql_str = 'SELECT au_lname AS ' + convert(varchar(30), @pID) + ' FROM authors' execute(@sql_str) But note, however, that an alias cannot start with a number, it must start with an alphabetic character. Thanks, Tom Upvote 0 Downvote
Ahhh.. sorry, I misunderstood the quesiton... You could use execute to build the select string and execute the string as in: USE PUBS GO DECLARE @sql_str varchar(255) SET @pID='A015' -- cant start with a number, so I made it start with a char. Set @sql_str = 'SELECT au_lname AS ' + convert(varchar(30), @pID) + ' FROM authors' execute(@sql_str) But note, however, that an alias cannot start with a number, it must start with an alphabetic character. Thanks, Tom
Nov 8, 2000 #6 TomSark MIS Oct 19, 2000 448 US And.. i forgot to add the @pid declaration in the code above... geesh.. having a bad day... stayed up too late last night watching the election... Tom Upvote 0 Downvote
And.. i forgot to add the @pid declaration in the code above... geesh.. having a bad day... stayed up too late last night watching the election... Tom
Nov 9, 2000 Thread starter #7 Bamboosch Programmer Jun 23, 2000 6 DE Oh yes, many thanks for your help! Also I found a solution to use only numbers in column names: USE PUBS GO DECLARE @sql_str varchar(255) DECLARE @pid varchar(30) SET @pID='[15]' -- If you use [ ] brackets inside the ', numbers are possible, too. SET @sql_str = 'SELECT au_lname AS ' + convert(varchar(30), @pID) + ' FROM authors' EXECUTE(@sql_str) without your tip it would have been a very very long night... ;-) bamboosch Upvote 0 Downvote
Oh yes, many thanks for your help! Also I found a solution to use only numbers in column names: USE PUBS GO DECLARE @sql_str varchar(255) DECLARE @pid varchar(30) SET @pID='[15]' -- If you use [ ] brackets inside the ', numbers are possible, too. SET @sql_str = 'SELECT au_lname AS ' + convert(varchar(30), @pID) + ' FROM authors' EXECUTE(@sql_str) without your tip it would have been a very very long night... ;-) bamboosch
Nov 9, 2000 #8 TomSark MIS Oct 19, 2000 448 US Glad to help... name a kid after me or something LOL Tom Upvote 0 Downvote