Hi all im pretty new to SQL.
This is the current simple query, which returns the carrier with lowest number of haulage shipments in the uk for a particular brewery.
USE Rep_UK
SELECT count(DISTINCT Load_ID) AS STO
,carrierName
FROM dbo.main_table_uk AS main
WHERE Origin_Location_ID LIKE 'GB%'
AND Destination_Location_ID LIKE 'GB%'
GROUP BY carrierName
ORDER BY STO
I need to in addition to this, also filter by a date range which needs to be 199 days previous from the current (today) date.
We have a 'delivery date' table which contains dates in the following format dd/mm/yyyy.
I understand I need to likely convert this first to INT then minus 199 from current date but cannot work out how to do it, any help much appreciated!
If I missed something please let me know!
using SQL server.
EDIT: I tried to use WHERE deliveryDate < DateAdd(dd, -199, GetDate()) but I got an error
EDIT found what I was looking for by adding
WHERE convert(DATE, main.deliveryDate, 103) >= GETDATE()-199
this worked and did not return error, many thanks for all help.