Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Todays date required in list from query 2

Status
Not open for further replies.

Cpreston

MIS
Mar 4, 2015
972
GB
Hi

I thought I had sorted this from an earlier post but looks like I have not. I have this query which up until 2 hours ago was working fine.

it was giving the daterequired starting from todays date, now it is giving tomorrow date?

Could someone advise why this is happening, it should display 2015-06-16 but it is starting at 2015-06-17

SELECT TOP (100) PERCENT dbo_OrderHeader.DateRequired, ProductGroup_1.Name AS [Level 1], dbo.ProductGroup.Name AS [Level 2], SUM(dbo_OrderLine.TotalVolume)
AS [Total Volume]
FROM dbo_OrderHeader INNER JOIN
dbo_OrderLine ON dbo_OrderHeader.OrderID = dbo_OrderLine.OrderID INNER JOIN
dbo.Product ON dbo_OrderLine.ProductID = dbo.Product.ProductID INNER JOIN
dbo.ProductGroup ON dbo.Product.ProductGroupID = dbo.ProductGroup.ProductGroupID INNER JOIN
dbo.ProductGroup AS ProductGroup_1 ON dbo.ProductGroup.ParentID = ProductGroup_1.ProductGroupID
WHERE (dbo_OrderHeader.StockIssued = 0) AND (ProductGroup_1.Name = 'Arborflor') AND (dbo_OrderHeader.DateRequired >= GETDATE() - 1) OR
(dbo_OrderHeader.StockIssued = 0) AND (dbo_OrderHeader.DateRequired >= GETDATE() - 1) AND (dbo.ProductGroup.Name IN ('mouldings', 'loose stock', 'Spindles',
'Newels', 'Handrail Kits', 'DeckAncillaries', 'DeckPosts', 'DeckRails', 'MDF Loose', 'Length stocks', 'MDF architraves loose', 'MDF skirtings loose',
'MDF windowboard loose')) AND (dbo_OrderHeader.DateRequired >= CAST(GETDATE() - 1 AS DATE)) AND (dbo_OrderHeader.DateRequired <= DATEADD(day, 7,
CAST(GETDATE() - 1 AS DATE)))
GROUP BY dbo_OrderHeader.DateRequired, dbo.ProductGroup.Name, ProductGroup_1.Name
ORDER BY dbo_OrderHeader.DateRequired



Thanks

 
Hi

Yes I have rows for that date for 2015-06-16

Thanks
 
Hi

After further investigation I have found if I take this out of the query

AND (ProductGroup_1.Name = 'Arborflor')

I get all other groups for 2015-06-16 so obviously no results match for Arboflor.

Therefore my next question would be if there is nothing to result back is there away to display a 0 total, and if so how do I out that in the query.

Thanks
 
There is NOTHING for Arborflor for Today, so how could ZERO which is SOMETHING be a value for NOTHING?

What You'ld need to do is join to your query, a list of all the dates you want SOMETHING for.

This is almost like Sam Harris defining NOTHING as a quantum vacuum, which is SOMETHING!!!
 
In your where clause, there is an OR condition which is almost certainly causing your problem.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Try changing your where clause to this:

Code:
WHERE [!]([/!](dbo.OrderHeader.StockIssued = 0) AND (ProductGroup_1.Name = 'Arborflor') AND (dbo.OrderHeader.DateRequired >= GETDATE() - 1) [!])[/!] OR [!]([/!]
(dbo.OrderHeader.StockIssued = 0) AND (dbo.OrderHeader.DateRequired >= GETDATE() - 1) AND (dbo.ProductGroup.Name IN ('mouldings', 'loose stock', 'Spindles', 
'Newels', 'Handrail Kits', 'DeckAncillaries', 'DeckPosts', 'DeckRails', 'MDF Loose', 'Length stocks', 'MDF architraves loose', 'MDF skirtings loose', 
'MDF windowboard loose')) AND (dbo.OrderHeader.DateRequired >= CAST(GETDATE() - 1 AS DATE)) AND (dbo.OrderHeader.DateRequired <= DATEADD(day, 7, 
CAST(GETDATE() - 1 AS DATE))) [!])[/!]

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top