Reputation: 85
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
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