I have this part of the code:
IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = REPLACE(@TableName, 'form.', '')
AND COLUMN_NAME = 'INSTID'))
BEGIN
SET @sql = 'SELECT COUNT(*) FROM '+ @TableName + ' WHERE id = ' + str(@id) + ' AND INSTID = ' + @in
EXEC sp_executesql @sql, N'@instid2 int output', @instid2 output
END
But I get this error:
Conversion failed when converting the nvarchar value 'Select COUNT(*) from form.PRO_TTZ where id = 1070 and INSTID = ' to data type int.