存储过程空值或列中的零值

时间:2015-09-01 13:15:53

标签: stored-procedures

我有一个存储过程,它用于更新表,当我执行它时,它会为某些列带来空值或零值。这是使用的逻辑

IF OBJECT_ID('tempdb..#exxPresessions_john') IS NOT NULL
    DROP TABLE #exxPresessions_john

SELECT c.claim_id,
       c.completed_date,
       wp.createdon,
       COUNT(DISTINCT wp.WebSessionId) AS websessions
INTO #exxPresessions_john
FROM dbo.web_PageviewsID wp WITH (NOLOCK)
JOIN #CliamID_john c WITH (NOLOCK)
  ON c.claim_id = wp.claimid
WHERE ClaimType IS NOT NULL
  AND c.completed_date > wp.createdon 
GROUP BY 
   claim_id,
   completed_date,
   createdon
ORDER BY claim_id;

CREATE INDEX idx_index2 ON #WebPresessions_nosa (claim_id);

这是条件
completed_date > created_date .it返回NULL,因为completed_date为NULL或Zero

我尝试了这个,但它没有工作
and ISNULL (c.completed_date,0)> wp.createdon

1 个答案:

答案 0 :(得分:0)

您需要再添加一个这样的条件:

WHERE ClaimType IS NOT NULL
AND c.completed_date is not null    --Removes the null completed_date  
  AND c.completed_date > wp.createdon