3
讓我們考慮這個基本插入條件插入SQL服務器
insert into TableName (Col1,Col2,Col3) values (Val1,Val2,Val3)
我想該插入物做只有當VAL1!= null,並且VAL3!= NULL 如何做到這一點?
讓我們考慮這個基本插入條件插入SQL服務器
insert into TableName (Col1,Col2,Col3) values (Val1,Val2,Val3)
我想該插入物做只有當VAL1!= null,並且VAL3!= NULL 如何做到這一點?
這是你在找什麼?
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
insert into TableName (Col1,Col2,Col3) select Val1,Val2,Val3 where Val1 is not null and Val3 is not null