sql if value is null not equal does not work

jim brown 271 Reputation points
2020-08-18T15:27:27.96+00:00

I have the below query, but the AND pd.FROMLOC <> 'DMS' does not work if the column has {null} is there a workaround?

SELECT pd.wavekey, pd.orderkey, o.externorderkey, pd.pickdetailkey, pd.status, pd.fromloc, pd.loc, pd.sku, pd.qty, pd.adddate, SUBSTR(o.c_zip,1,3), O.SUSR4, od.cartonbreak  
FROM sprtict.pickdetail pd  
Join sprtict.ORDERS O on O.ORDERKEY = PD.ORDERKEY  
Join sprtict.ORDERDETAIL OD on OD.ORDERKEY = O.ORDERKEY and od.ORDERLINENUMBER = pd.ORDERLINENUMBER  
WHERE(PD.adddate BETWEEN (TRUNC(SYSDATE-1) + 21/24) AND (TRUNC(SYSDATE) + 21/24))  
AND od.cartonbreak NOT IN ('FLOORPICK', 'LIFTPICK', 'STRINGERS')  
AND pd.FROMLOC <> 'DMS'  
AND pd.LOC <> 'DMS'  
AND O.SUSR4 = '3P01'  
AND pd.wavekey = '0001520762'  
AND o.externorderkey = 'SP000044662873'  

18396-screenshot2.jpg

18329-screenshot.jpg

Developer technologies | Transact-SQL
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
0 comments No comments
{count} votes

Answer accepted by question author
  1. jim brown 271 Reputation points
    2020-08-18T15:55:45.207+00:00

    Fixed, and nvl(pd.fromloc, 'NullFROMLOC') <> 'DMS'

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tom Phillips 17,776 Reputation points
    2020-08-18T18:54:03.463+00:00

    I nvl is an Oracle command. This is a MS SQL Server forum.

    However, I suggest you read this:
    https://www.red-gate.com/simple-talk/sql/t-sql-programming/how-to-get-nulls-horribly-wrong-in-sql-server/

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.