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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not getting Date filter right. 1

Status
Not open for further replies.

AuctionLamb

Programmer
Feb 16, 2005
65
ZA
Hi guys!!

I have a problem with my SQL statement, why does it not bring back the QuoteDate specified in my WHERE clause? Can you help me please.......

SELECT QUOTES.FK_sCust AS Customer, QUOTES.FK_sBranch AS BRANCH, QUOTES.dQuote_Date AS QuoteDate
FROM dbo.JOBS
LEFT JOIN dbo.QUOTES
ON dbo.JOBS.FK_iQuote_id = dbo.QUOTES.PK_iQuote_id
LEFT JOIN Staging.dbo_OnlineOrders OO
ON dbo.JOBS.CUST_PO_NUM = OO.jobNr
LEFT JOIN vw_DespatchedGoodsReceived
ON JOBS.JobNumber = vw_DespatchedGoodsReceived.jobnumber
WHERE JOBS.JobNumber <> ''
AND(QUOTES.FK_sCust = 'ZDAM')
OR (QUOTES.FK_sCust = 'INTEC')
OR (QUOTES.FK_sCust = 'DAMELIN DBN')
OR (QUOTES.FK_sCust = 'INTEC DBN')
AND (QUOTES.dQuote_Date >= '2004-03-01')
 
You need to have a close look at how you are bracketing the where clause a the moment you are getting

(Job Number = "" and Quotes = ZDAM)
Or
(Quotes = INTEC)
Or
(Quotes = DAMELIN)
or
(Quotes = INTEC and date = 2004-03-01)
 
To make it simpler, use IN ('ZDAM', blah blah ) - then you'll have no problems with AND/OR precendence... for now :X

------
heisenbug: A bug that disappears or alters its behavior when one attempts to probe or isolate it
schroedinbug: A bug that doesn't appear until someone reads source code and realizes it never should have worked, at which point the program promptly stops working for everybody until fixed.

[ba
 
Code:
SELECT QUOTES.FK_sCust AS Customer, QUOTES.FK_sBranch AS BRANCH, QUOTES.dQuote_Date AS QuoteDate
FROM dbo.JOBS
LEFT JOIN dbo.QUOTES
    ON dbo.JOBS.FK_iQuote_id = dbo.QUOTES.PK_iQuote_id
LEFT JOIN Staging.dbo.OnlineOrders OO
    ON dbo.JOBS.CUST_PO_NUM = OO.jobNr
LEFT JOIN vw_DespatchedGoodsReceived
    ON JOBS.JobNumber = vw_DespatchedGoodsReceived.jobnumber
WHERE JOBS.JobNumber <> ''
	AND QUOTES.FK_sCust IN ('ZDAM', 'INTEC', 'DAMELIN DBN', 'INTEC DBN')
	AND QUOTES.dQuote_Date >= '2004-03-01'

------
heisenbug: A bug that disappears or alters its behavior when one attempts to probe or isolate it
schroedinbug: A bug that doesn't appear until someone reads source code and realizes it never should have worked, at which point the program promptly stops working for everybody until fixed.

[ba
 

job number = "" and quotes in(ZDAM, Intec,....) and Date = 01-04-2004
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top