向表和存储过程添加了新字段,现在过程不返回任何结果

时间:2013-05-08 16:25:14

标签: sql sql-server-2008-express

我最近在我的表格中添加了一个Deleted列,然后想要添加一个额外的where子句,但现在我没有得到任何结果(它在我添加deleted之前返回了结果列)

SELECT 
    tblEquipment.*, tblUsers.* 
FROM 
    tblEquipment 
INNER JOIN 
    tblUsers ON tblEquipment.UserID = tblUsers.ID 
WHERE  
    (UPPER(tblUsers.Dept) = 'ASPIRE' OR UPPER(tblUsers.Dept) = 'DEVELOPMENT') 
    AND (AssetType = 'WORKSTATION' OR AssetType = 'LAPTOP') 
    AND (tblEquipment.Deleted != 1)  
ORDER BY 
    Username

感谢您的帮助

2 个答案:

答案 0 :(得分:2)

如果每条记录DeletedNULL,则您的条件应为:

AND (tblEquipment.Deleted != 1 OR tblEquipment.Deleted IS NULL)  

答案 1 :(得分:1)

我假设您没有填充新列,因此每条记录都有NULL作为值。

取决于RDMS如何评估NULL
tblEquipment.Deleted != 1

可能是罪魁祸首。

更新:

以下内容应解决您的问题:

ISNULL(tblEquipment.Deleted,0) != 1