Abhilash Srivastava
Abhilash Srivastava

Reputation: 85

SQL Query Incorrect syntax near @parameter

Declare @motherTongue varchar(20) = 'Doesn''t Matter' 

if (@motherTongue = 'Doesn''t Matter') 
begin
    @motherTongue = null 
end

I am getting an error:

Incorrect syntax near '@motherTongue' error

I am just a beginner.

Upvotes: 1

Views: 909

Answers (1)

Pரதீப்
Pரதீப்

Reputation: 93734

You need to use SET/Select to assign value to a variable

if(@motherTongue = 'Doesn''t Matter') 
Begin 
SET @motherTongue = null  --Here 
End

But I will do this using CASE instead of IF

SET @motherTongue = case when @motherTongue = 'Doesn''t Matter' then NULL END

You can use NULLIF as well

SET @motherTongue = NULLIF(@motherTongue,'Doesn''t Matter')

Upvotes: 2

Related Questions