当B为空时,排除A列的记录

时间:2015-08-25 14:20:12

标签: sql-server

如果列中的记录存在null,则需要查询帮助我从列A中排除记录。

让我们说我有两行是A列,名为" test"它们的B列值分别为1和null。下面是一个查询,我在对象ID上工作的是A列,而endversion在我的场景中是B列。

select b.PortID, 
       max(endversion)as EndVersion, 
       d.ShortName as RuleName 
from xr.ObjectPropertyValue a 
       join moxyportfolio b on a.objectid=b.portkey 
       join xr.AssignAllObjectsRule c on a.Objectclassid=c.ObjectClassID -- can replace with xr.assignobjectrule if it's rule is not assigned to all portfolios.
       join xr.rulebase d on c.RuleID=d.RuleID 
where objectid in (select objectid from xr.objectpropertyvalue where endversion is not null) 
group by a.ObjectId, b.portid,d.ShortName

2 个答案:

答案 0 :(得分:0)

您可以使用067 ----------------------------------- Louis Tsai home 0809097

执行此操作
HAVING

答案 1 :(得分:0)

如果列B不为空,则仅选择列A的值(否则不选择任何其他内容):

 SELECT COLA
 FROM TABLE
 WHERE COLB IS NOT NULL

如果列B不为空,则仅为列A选择值(否则为null):

 SELECT CASE WHEN COLB IS NOT NULL THEN COLA ELSE NULL END AS COLA
 FROM TABLE