0

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
AlexW
  • 2,843
  • 12
  • 74
  • 156
  • microsoft sqlserver 2008 express, i got my results until i added the deleted not equal to 1 part, currently deleted is null on all records – AlexW May 08 '13 at 16:28

2 Answers2

2

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

AND (tblEquipment.Deleted != 1 OR tblEquipment.Deleted IS NULL)  
Lamak
  • 69,480
  • 12
  • 108
  • 116
1

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
Jeff B
  • 155
  • 7