Apologies if my question is not clear, I am new to this!
I've got data going back 3 years and I want the 364DaysFlag column to return 1 if the date within the InsertDateTime column (which consists of both the date and time) is within the last 364 days and to return 0 if the InsertDateTime is older than 354 days.
Just to make it clear, the Transaction.tbl.Flag table is dynamic/live so everyday the most recent day is added and this is where I come unstuck in order to get it to work!
Below is the incorrect code (which runs but does not do what I want) that I've used and where I made it bold is where it needs updating.
SELECT TransactionDate, TotalCustomers, [1 as 364DaysFlag], InsertDateTime
INTO Transaction.tbl.Flag
FROM Performance.Sales.Total
Please could someone advise on how I can get this to work? Do I need to use an IF function or something else? DO I need a DATEADD and/or GETDATE function? I am fairly new to SQL and still learning! :)
Aucun commentaire:
Enregistrer un commentaire