I'm trying to create a SQL statement, which calculates how many days a delivery of undelivered products are delayed relative to the current date. The result should show the order number, order date, product number and the number of delay days for the order lines where the number of days of delay exceeds 10 days.
Here is my SQL statement so far:
SELECT
Orderhuvuden.ordernr,
orderdatum,
Orderrader.produktnr,
datediff(day, orderdatum, isnull(utdatum, getdate())) as 'Delay days'
FROM
Orderhuvuden
JOIN
Orderrader ON Orderhuvuden.ordernr = Orderrader.ordernr AND utdatum IS NULL
What I have a problem with is to solve how to show the delayed days that exceeds 10 days. I've tried to add something like:
WHERE (getdate() - orderdatum) > 10
But it doesn't work. Does anyone know how to solve this last step?
Add this to your where clause:
AND DATEDIFF(day, orderdatum, getdate()) > 10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With