I\'m receiving an error:
Conversion failed when converting the varchar value \'INSERT INTO TableRowCount (IntFieldID, DecimalField) SELECT \'to data t
You need to convert your @Start
to a varchar
.
DECLARE @sql NVARCHAR(MAX)
SET @sql = 'INSERT INTO TableRowCount (IntFieldID, DecimalField)
SELECT ' + CAST(@start as nvarchar(20)) +', COUNT(*)
FROM ' + @conn
SQL Server implicitly converts between datatypes on concatenation or addition based on some fairly complex criteria. Suffice to say if you try to combine an int
and a string it will always attempt to convert the string to an int
unless you tell it otherwise explicitly.
Below is a conversion chart for your reference from MSDN.