I'm using a Dynamic Query to alter a temp table in Stored Procedure. I'm using Values to name the columns from a Cursor.
My problem is that the values are numbers and will contain negivitve numbers. ex:-55, -125 etc.
When the table is altered with the column name that has a "-",
I get a syntax error: "Incorrect syntax near '-'."
I have casted the value to a string and even added a "t" in front of the value, but still get the error.
Any help would be great.
--@rtemps = -55
DECLARE tempvalue_cursor CURSOR FOR
SELECT R1 From dbo.LVWAREQUALIMPORT
SET @rtemps = CAST(@rtemps AS VARCHAR(10))
exec ('ALTER TABLE #t ADD T'+ @rtemps+' VARCHAR(10) NULL')