Avatar of RichardAtk
RichardAtk
 asked on

SQL View / Qtry

SELECT     DW_Account, [Forecast Date], [Item No.], SUM([Forecast Quantity]) AS Expr1, [Location Code]
FROM        dbo.[NAV_dbo_Production Forecast Entry_R]
GROUP BY DW_Account, [Forecast Date], [Item No.], [Location Code]
HAVING     (SUM([Forecast Quantity]) > 0)

Hi I have this view that I would like to limit by only bringing in data after the 15th of the current month  or setting forecast qty to 0 for anything before this.  So for March we are on the 22nd I want to bring back all the data after 15th March 2017 when we get into April qry stays the same but after April 15h the report then only brings back data after April 15th and so on with each change of month.  Guess it's
greater than 15th of current month/year after current day of the month passes 15.
Microsoft SQL Server

Avatar of undefined
Last Comment
Vitor Montalvão

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
YZlat

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
RichardAtk

ASKER
Perfect many thanks
Vitor Montalvão

Something like this?
SELECT DW_Account, [Forecast Date], [Item No.], SUM([Forecast Quantity]) AS Expr1, [Location Code]
FROM dbo.[NAV_dbo_Production Forecast Entry_R]
WHERE (DAY(GETDATE()) >= 15 AND [Forecast Date] >= DATEFROMPARTS(YEAR(GETDATE()),MONTH(GETDATE()),15))
	OR (DAY(GETDATE()) < 15 AND [Forecast Date] >= DATEFROMPARTS(YEAR(DATEADD(month,-1,GETDATE())),MONTH(DATEADD(month,-1,GETDATE())),15))
GROUP BY DW_Account, [Forecast Date], [Item No.], [Location Code]
HAVING (SUM([Forecast Quantity]) > 0)

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck