2010-07-14 3 views
3

는의 난이 삽입 만 널 (null) = VAL1! = null이 Val3! 어떻게 이러한 목표를 달성하기 위해 수행해야 할 기본적인 삽입조건부 삽입 SQL 서버

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

를 생각해 보자?

답변

3

이게 당신이 찾고 있는게 있나요?

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

두 번째 생각에는 BeachBlocker의 답변도 매우 좋습니다. 조금 수정했습니다 :

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