TSQL 'Invalid column name' error on value of sproc parameter

Posted by Daria on Stack Overflow See other posts from Stack Overflow or by Daria
Published on 2010-03-18T19:36:25Z Indexed on 2010/03/18 19:41 UTC
Read the original article Hit count: 414

Filed under:
|

here's my code:

DECLARE @SQL varchar(600)

SET @SQL = 
'SELECT     CategoryID, SubCategoryID, ReportedNumber
FROM    tblStatistics
WHERE   UnitCode = ' + @unitCode +
' AND   FiscYear = ' + @currYEAR

EXEC (@SQL)

When i run this sproc with unitCode = 'COB' and currYEAR = '10', i get the following error:

Invalid column name 'COB'.

Does anyone know why?

thx!

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about tsql