Total newbie question, but i'm having some trouble executing the following dynamic sql statement. The folowing represents an example of the piece of code...
CREATE TABLE #Temp([VID] INT)
INSERT INTO #Temp VALUES(6565)
ALTER TABLE #Temp ADD Counter INT
DECLARE @SQL VARCHAR(250)
DECLARE @VID INT
DECLARE @COUNTERVAR INT
SET @VID='6585'
SET @COUNTERVAR=1
SET @SQL = 'UPDATE #Temp SET COUNTER = '+ @COUNTERVAR +' WHERE VID='+ @VID + ''
EXEC (@SQL)
Below is the error message that I am receiving
Conversion failed when converting the varchar value 'UPDATE #Temp SET COUNTER = ' to data type int.
CREATE TABLE #Temp([VID] INT)
INSERT INTO #Temp VALUES(6565)
ALTER TABLE #Temp ADD Counter INT
DECLARE @SQL VARCHAR(250)
DECLARE @VID INT
DECLARE @COUNTERVAR INT
SET @VID='6585'
SET @COUNTERVAR=1
SET @SQL = 'UPDATE #Temp SET COUNTER = '+ @COUNTERVAR +' WHERE VID='+ @VID + ''
EXEC (@SQL)
Below is the error message that I am receiving
Conversion failed when converting the varchar value 'UPDATE #Temp SET COUNTER = ' to data type int.