I am looking to insert any timestamp and to return a column that returns a date of Sunday ( start of the week). I reviewed the answer in the thread Start the first day of the week as Sunday in SQL but keep getting errors.
My SQL is below. "received_day" is my unique timestamp that I would look to convert to Sunday. Any guidance appreciated.
SELECT received_day
, distributor_id
, warehouse_id
, sum(quantity_unpacked) as qty
, Case
When distributor_id IN ('FRTMU','I20TQ','P294D','AA05E','WB3JB') THEN 'CHICAGO'
ELSE 'WRONG' END AS GEO
FROM TBL NAME
WHERE received_day between TO_DATE('20201227', 'YYYYMMDD') and TO_DATE ('{RUN_DATE_YYYYMMDD}', 'YYYYMMDD')
GROUP BY received_day, distributor_id, warehouse_id, supplier_order_type_id
Limit 100
I have also a DateFirst approach with no luck:
SET DATEFIRST 7,
SELECT cast (received_day AS datetime2) AS SelectDate
,DATEPART (dw,received_day) As DayofWeek
,received_day
, distributor_id
, warehouse_id