March 18, 2003 at 1:12 am
When I run
use northwind
DECLARE @CharVariable CHAR(9)
SET @CharVariable = 'Beverages'
select * from categories where categoryname = @CharVariable
in Query Analyzer (sql 2k) everything works fine. But if I change the last line to read
exec('select * from categories where categoryname =' + @CharVariable)
I get
Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'Beverages'.
What am I doing wrong?
TIA,
Bill
March 18, 2003 at 1:43 am
You're missing quotation-marks.
use northwind
DECLARE @CharVariable CHAR(9)
SET @CharVariable = 'Beverages'
exec('select * from categories where categoryname = ''' + @CharVariable + '')
--
Chris Hedgate @ Apptus Technologies (http://www.apptus.se)
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply