delphidestructor
Programmer
- Oct 20, 2000
- 67
Can anyone tell me why the value of @var2 can be used to execute a query but the value of @var1 cannot? Is there anyway to force sql server 2000 to recognize the value in @var1 instead of trying to read this as a column name?
declare @var1 varchar(50)
declare @var2 int
select @var1 from a_table where a_column = @var2
I know I can do an exec statement and build a query string but ultimately I want to work with the value returned and if I do this then I cannot get the value into a variable.
declare @var1 varchar(50)
declare @var2 int
declare @realvar real
select @realvar = @var1 from a_table where a_column = @var2
I want to pass in a column name or an equation that uses more than one field. Please do not reply if you are going to give me a lecture on dynamic sql. A no this cannot be done or yes it can and this is how, would be great. Thank you in advance. Mike.
Mike
declare @var1 varchar(50)
declare @var2 int
select @var1 from a_table where a_column = @var2
I know I can do an exec statement and build a query string but ultimately I want to work with the value returned and if I do this then I cannot get the value into a variable.
declare @var1 varchar(50)
declare @var2 int
declare @realvar real
select @realvar = @var1 from a_table where a_column = @var2
I want to pass in a column name or an equation that uses more than one field. Please do not reply if you are going to give me a lecture on dynamic sql. A no this cannot be done or yes it can and this is how, would be great. Thank you in advance. Mike.
Mike