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.
RichardAtkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

YZlatCommented:
use

select cast(convert(varchar(10), dateadd(dd,datediff(dd,datepart(dd,getdate()),15),getdate()), 101) as datetime)

Open in new window



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  [Forecast Date] > cast(convert(varchar(10), dateadd(dd,datediff(dd,datepart(dd,getdate()),15),getdate()), 101) as datetime)
GROUP BY DW_Account, [Forecast Date], [Item No.], [Location Code]
HAVING     (SUM([Forecast Quantity]) > 0)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RichardAtkAuthor Commented:
Perfect many thanks
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
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

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.