No I don't have that field. I wish I did that would make it easier
Main Topics
Browse All TopicsYou guys helped me build this query, now I have one adjustment that needs to be made. Again, the reason is trending. We have tested this on all products and it's working great, except for new products. Since we're looking at the last 120 days here, it returns 2 months of 0 sales days preceding the actual day we started selling it 2 months ago.
I need to keep the days with 0 sales between regular days, but I want to get rid of all the preceding ones.
Let's say we're excluding all the days starting from the beginning of the month up until the first day of actual sales. From then on, we include everything.
Here's the kicker. Some returning experts might remember that I'm using iDashboards, and the SELECT statement cannot have UDFs or declared tables. This is the reason for the subqueries as tables in my code below. So, I'm not sure if this is even possible, but you guys continue to surprise me!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
try this
SELECT d.dates AS InvoiceDate
, i.ItemCode
, SUM(isnull(AR_InvoiceHisto
FROM (select dateadd(dd,datediff(dd, 0, getdate()),-number) as dates from master..spt_values where number between 0 and 120 and type = 'p' ) D
CROSS JOIN (select ItemNumber AS ItemCode, StartDay from InventoryDays,
(Select ItemCode, min(InvoiceDate) StartDay from AR_InvoiceHistoryHeader IH join AR_InvoiceHistoryDetail ID
on IH.InvoiceNo = ID.InvoiceNo group by ID.Itemcode) A where A.ItemCode = InventoryDays.ItemNumber
) I
LEFT JOIN AR_InvoiceHistoryHeader ON D.dates = datediff(dd,0,AR_InvoiceHi
LEFT JOIN AR_InvoiceHistoryDetail ON AR_InvoiceHistoryHeader.In
AND AR_InvoiceHistoryDetail.It
where d.dates >= i.StartDay
GROUP By d.dates, i.ItemCode
ORDER BY 1,2
Business Accounts
Answer for Membership
by: appariPosted on 2009-10-19 at 22:13:33ID: 25611193
do you have actual selling start day of an item in the table?
ryDetail.Q uantityOrd ered,0)) as Qty storyHeade r.InvoiceD ate) AND AR_InvoiceHistoryHeader.In voiceType = 'IN' voiceNo = AR_InvoiceHistoryDetail.In voiceNo emCode = i.ItemCode
suppose you have that field in inventorydays table change the query like this and try it.
SELECT d.dates AS InvoiceDate
, i.ItemCode
, SUM(isnull(AR_InvoiceHisto
FROM (select dateadd(dd,datediff(dd, 0, getdate()),-number) as dates from master..spt_values where number between 0 and 120 and type = 'p' ) D
CROSS JOIN (select ItemNumber AS ItemCode, StartDay from InventoryDays) I
LEFT JOIN AR_InvoiceHistoryHeader ON D.dates = datediff(dd,0,AR_InvoiceHi
LEFT JOIN AR_InvoiceHistoryDetail ON AR_InvoiceHistoryHeader.In
AND AR_InvoiceHistoryDetail.It
where d.dates >= i.StartDay
GROUP By d.dates, i.ItemCode
ORDER BY 1,2