December 28, 2009 at 2:47 pm
hi, plz execute above code in Query analyzer.
declare @year char(4)
Declare @visa varchar(25)
declare @visa1985 varchar(25)
set @visa ='56'
Set @year ='1985'
select @visa = '@visa' + ''+@year+''
Print @visa
Exec('select '''+@visa+'''')
It will display @visa1985 as output but instead i want the value of @visa1985
to be printed. Can any one help me how to do that? Thanks
December 28, 2009 at 3:54 pm
ummm not really. i have years starting from 1985 to 2009 and it will increase every year so next year 2010 will be added.
@visa1985 is a parameter like wise we have parameters upto @visa2009. And all these parameters have different values that user will pass from SP.
I am trying to minimize my code here thats why i m dynamically selecting @visa1985, @visa1986 from my while loop but i want actual value of @visa1985 to be displayed.
I hope u got what i want to tell. Thanks
December 28, 2009 at 4:20 pm
dallas13
Sorry, but I am rather dense, and do not understand your amplified explanation. Some items is question:
1. Does user pass in a single parameter value?
2. If more than one parameter value, must values for each declared parameter be supplied?
3. You have posted this question to a SQL 2005 forum and yet want to run the code in Query Analyzer which is a SQL 2000 interface. Which is it 2000 ot 2005?
How about posting your T-SQL code in its entirety and maybe some one can and will assist you further.
December 28, 2009 at 4:28 pm
declare @year char(4)
Declare @visa varchar(25)
declare @visa1985 varchar(25)
set @visa ='56'
Set @year ='1985'
--select @visa = '@visa' + ''+@year+''
--Print @visa
--
--Exec('select '''+@visa+'''')
SELECT @visa
--Jeff Moden
Change is inevitable... Change for the better is not.
December 28, 2009 at 6:02 pm
Sorry, but I am rather dense, and do not understand your amplified explanation. Some items is question:
1. Does user pass in a single parameter value?
--no users can pass any number of parameters. They can pass @visa1985 =int, @visa1990 =null,
@visa1995 =int.means they can pass values and if they don’t want to then its null
2. If more than one parameter value, must values for each declared parameter be supplied?
3. You have posted this question to a SQL 2005 forum and yet want to run the code in Query Analyzer which is a SQL 2000 interface. Which is it 2000 ot 2005?
--its sql 2005 question.
I am still not able to get what I want from above code. I want @visa1985 = 56 or any int value that can be supplied and I don’t want @visa1985 = 561985. I hope I m able to explain it properly.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply