Si8 Si8 - 4 months ago 8
SQL Question

How to choose the 12 prior weeks in SQL

It had a lot of row with NULL value which I deleted using the following query:

/* DELETE EVERY ROW EXCEPT THE ROW WE NEED */
DELETE FROM [Database].[dbo].[Table]
WHERE
([Week Of*] IS NULL)


How do I write a query which will get the prior 12 weeks from the current rolling week and insert the
[F4]
value into a table

Si8 Si8
Answer

I ended up using the following which gave me the last 12 weeks (how ever I have to use 14 to get the 12 weeks. Still trying to figure out why:

SELECT CONVERT(VARCHAR(10),[Week Of*],110) AS [Date], [F18] AS [TOTALS] FROM [db].[DBO].[table] WHERE CONVERT(VARCHAR(10),[Week Of*],110) >= DATEADD(week, -14, GETDATE())
Comments