选择查询的多个条件

时间:2012-11-02 16:34:52

标签: sql sql-server-2008

我有一个select语句,我希望根据表中的其他值计算立方体积。但是我想检查pr.Length_mm或pr.Width_mm或pr.Height_mm先前是否为NULL。我查看了CASE语句,但它似乎只能一次评估一列。

SELECT 
      sa.OrderName,
      sa.OrderType,
      pr.Volume_UOM
 ,pr.Length_mm*pr.Width_mm*pr.Height_mm AS Volume_Cubic
 ,pr.Length_mm*pr.Width_mm AS Volume_Floor
 ,pr.Length_mm
 ,pr.Height_mm
 ,pr.Width_mm
FROM CostToServe_MCB.staging.Sale sa
LEFT JOIN staging.Product pr
ON sa.ID = pr.ID

3 个答案:

答案 0 :(得分:2)

SELECT pr.Volume_UOM
 ,pr.Length_mm*pr.Width_mm*pr.Height_mm AS Volume_Cubic
 ,pr.Length_mm*pr.Width_mm AS Volume_Floor
 ,pr.Length_mm
 ,pr.Height_mm
 ,pr.Width_mm
FROM CostToServe_MCB.staging.Sale sa
LEFT JOIN staging.Product pr
ON sa.ID = pr.ID
and pr.Length_mm is not null
and pr.Width_mm is not null
and pr.Height_mm is not null

答案 1 :(得分:2)

SELECT pr.Volume_UOM
 ,pr.Length_mm*pr.Width_mm*pr.Height_mm AS Volume_Cubic
 ,pr.Length_mm*pr.Width_mm AS Volume_Floor
 ,pr.Length_mm
 ,pr.Height_mm
 ,pr.Width_mm
FROM CostToServe_MCB.staging.Sale sa
    LEFT JOIN staging.Product pr ON sa.ID = pr.ID
where pr.Length_mm is not null and pr.Width_mm is not null and pr.Height_mm is not null

答案 2 :(得分:0)

where pr.Length_mm is not null 
  and pr.Width_mm is not null 
  and pr.Height_mm is not NULL
相关问题