2010-01-26 33 views
1

如何寫如果不存在,在SQL Server 2005語句以下條件如果不存在的語句在SQL Server 2005

如果@MeasurementId說值(1,2,3),這些都是現有的值下面的語句工作 但似乎當@ MeasurementId = 0時不工作...

If not exists(select Mat_Id,MeasurementId from MaterialQuantity where 
[email protected] and [email protected]) 

然而上述說法似乎並不如在MeasurementIdNULL值工作。你要知道MeasurementId是不是在這裏一個ForeignKey ...

如何分配NULL如果@MeasurementId爲0或使用@MeasurementId,因爲它是在 where聲明...

這是我 MaterialQuantity table

回答

3

除非我誤解了,我認爲你是在ISNULL語法之後:

If not exists(select Mat_Id,MeasurementId from MaterialQuantity where 
[email protected] and ISNULL(MeasurementId, 0) [email protected]) 
+0

@AdaTheDev工作... – 2010-01-26 13:27:34