Search code examples
sqlparametersquotes

sql with single quotes for parameter in where clause


I have below sql where I am trying to pass name parameter to sql, how can i append, I am getting syntax errors..

I have to @name in place of steeve

if @name not null BEGIN
        set @sql = @sql + ' AND name=''steeve''';
    END

Solution

  • if @name is not null then
    BEGIN
        set @sql = @sql + ' AND name=''' + @name + '''';
    END