1

次の条件のSQLServer2005に存在しない場合のステートメントの記述方法

@MeasurementIdが値(1,2,3)を言う場合、それらは以下のステートメントが機能する既存の値ですが、@ MeasurementId = 0の場合、機能しないようです...

If not exists(select Mat_Id,MeasurementId from MaterialQuantity where 
 Mat_Id=@Id and MeasurementId=@MeasurementId)

ただし、列にNULL値がある場合、上記のステートメントは機能しないようです。MeasurementIdここではForeignKeyMeasurementIdではないことに注意してください...

が0のNULL場合に割り当てる方法、またはステートメントでそのまま 使用する方法...@MeasurementId@MeasurementIdwhere

これは私のMaterialQuantityテーブルです

4

1 に答える 1

3

私が誤解していない限り、あなたはISNULL構文を採用していると思います。

If not exists(select Mat_Id,MeasurementId from MaterialQuantity where 
 Mat_Id=@Id and ISNULL(MeasurementId, 0) =@MeasurementId)
于 2010-01-26T13:24:00.740 に答える