문제

I recently added a Deleted column to my table and then wanted to add an additional where clause but now I'm not getting any results anymore (it returned results before I added the deleted column)

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

thanks for any help

도움이 되었습니까?

해결책

If Deleted is NULL for every record, your condition should be:

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

다른 팁

I'm assuming you haven't populated your new column, so every record has NULL as the value there. Depending on how your RDMS evaluates NULL, the

tblEquipment.Deleted != 1

is probably the culprit.

UPDATE:

The following should fix your problem:

ISNULL(tblEquipment.Deleted,0) != 1
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top