1
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.

2
  • Pretty sure that second @ shouldn't be there. Commented Mar 6, 2016 at 5:57
  • yes the red underline of syntax error is shown on second one only. Commented Mar 6, 2016 at 5:58

1 Answer 1

2

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.