DECLARE @SQL1 VARCHAR(MAX)
SET @SQL1='SELECT * FROM tblResponsibleEngineer WHERE ResponsibleEngineer='+CAST(@ResponsibleEngineer AS VARCHAR(500))+''
EXEC(@SQL1)
IF @@ROWCOUNT>0
BEGIN
SET @Result='EXIST'
above query fails execution due to the way i pass the parameter @ResponsibleEngineer in to the query. error is "Invalid column name TEST". TEST is the value i’m passing as the parameter value
@ResponsibleEngineer and there is no such column as TEST in the table.what the error when passing the parameter to insert query?
You need speach marks around the Parameter:
Otherwise you are generating:
Therefore its looking for a column
TEST. By having the parameter in speach marks you are generating:This query will then run a
WHEREclause where theResponsibleEngineercolumn equals the string valueTEST