3

Let's consider this basic insert

insert into TableName (Col1,Col2,Col3) values (Val1,Val2,Val3)

i want this insert to be done only if Val1 !=null and Val3!=null How to accomplish this?

2 Answers 2

3

Is this what you're looking for?

IF (Val1 is not null AND Val3 is not null)
BEGIN 
    insert into TableName (Col1,Col2,Col3) values (Val1,Val2,Val3)
END 

On second thought BeachBlocker's answer is quite nice too. I've modified it a little:

insert into TableName (Col1,Col2,Col3) select Val1,Val2,Val3 where Val1 is not null and Val3 is not null
Sign up to request clarification or add additional context in comments.

Comments

2
insert into TableName (Col1,Col2,Col3) select Val1,Val2,Val3 where Val1 is not null and Val3 is not null

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.