【问题标题】:If not exists statement in sql server 2005如果在 sql server 2005 中不存在语句
【发布时间】:2011-01-09 12:30:15
【问题描述】:

如何在sql server 2005中针对以下情况编写if not exists语句

如果@MeasurementId 说值 (1,2,3) 这些是现有值,则以下语句有效 但是当@MeasurementId=0 时它似乎不起作用......

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

但是,如果在 MeasurementId 列中有 NULL 值,则上述语句似乎不起作用。请注意MeasurementId 不是这里的外键...

如果@MeasurementId 为0,如何分配NULL 或使用@MeasurementId,因为它在 where声明...

这是我的 MaterialQuantity table

【问题讨论】:

    标签: sql-server-2005 select exists


    【解决方案1】:

    除非我误解了,否则我认为您使用的是 ISNULL 语法:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-01
      • 2013-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-05
      • 1970-01-01
      相关资源
      最近更新 更多