Hi All,
Would any one help me with this? Here is the portion of my stores procedure.
declare @something varchar(2000)
declare @lastname varchar(10)
declare @myvalue varchar(10)
declare @allvalue varchar(40)
set @myvalue = '''john'''
set @allvalue = '''Basketball'''
Set @something = 'SELECT ' + @lastname + ' = lname
FROM tableA WHERE fname = ' + @myvalue + ' AND activity in (' + @allvalue + ')'
exec(@something)
When I run the exec(@something) it does not work. But when I take the variable @lastname out of
statement, it comes back with some value.
Like this and it works.
Set @something = 'SELECT lname
FROM tableA WHERE fname = ' + @myvalue + ' AND activity in (' + @allvalue + ')'
exec(@something)
The point is , I need this variable @lastname value to set with lname so I can track
later in my stored procedures.
I am not sure that I did the right way as the first statement. Please help.
John
Would any one help me with this? Here is the portion of my stores procedure.
declare @something varchar(2000)
declare @lastname varchar(10)
declare @myvalue varchar(10)
declare @allvalue varchar(40)
set @myvalue = '''john'''
set @allvalue = '''Basketball'''
Set @something = 'SELECT ' + @lastname + ' = lname
FROM tableA WHERE fname = ' + @myvalue + ' AND activity in (' + @allvalue + ')'
exec(@something)
When I run the exec(@something) it does not work. But when I take the variable @lastname out of
statement, it comes back with some value.
Like this and it works.
Set @something = 'SELECT lname
FROM tableA WHERE fname = ' + @myvalue + ' AND activity in (' + @allvalue + ')'
exec(@something)
The point is , I need this variable @lastname value to set with lname so I can track
later in my stored procedures.
I am not sure that I did the right way as the first statement. Please help.
John