Your date calculation may not produce the correct results.
Is the case of this code correct? Does it match the database? I’m guessing that your database is case-insensitive, but it’s infinitely more readable if you write your code to match the objects.
Is this database your design? The names are pretty bad. There are keywords being used for object names. That’s probably not a good idea.
DECLARE @StartDate datetime
This may not produce the correct results.
If there is a time portion of the date, you may not
be getting all of the records.
That’s assuming that you want the full day.
SELECT @StartDate = DATEADD(day, 1, P.VDATE)
FROM [period] P
,D.EIDE AS EISD
FROM ord H
INNER JOIN loc D ON H.ORDER_NO = D.ORDER_NO
INNER JOIN item IM ON D.ITEM = IM.ITEM
INNER JOIN cls C ON IM.CLASS = C.CLASS
INNER JOIN sps S ON H.SUPPLIER = S.SUPPLIER
INNER JOIN dps DS ON IM.DEPT = DS.DEPT
H.STATUS = ‘C’
AND IM.ITEM_LEVEL = IM.TRAN_LEVEL
AND D.EIDE > @StartDate
AND EXISTS (SELECT *
FROM SHIPMENT SSN
WHERE SSN.order_no = H.order_no
,sasn.ASN –Is this correct? It is not in the select
D.EIDE –Your old syntax is no longer supported