954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Where clause error

Guys,

When i run this sscript i got an error in Where clause?
Where should be place this where clause?

SELECT p.ESN, p.ReturnDate,s.Receiptdate,e.Shipdate
FROM USProductRecovery p with (nolock)
OUTER APPLY((SELECT TOP 1 Receiptdate
FROM ESNSalvReceipts s with (nolock)
WHERE ESN = p.ESN
AND Receiptdate > p.Returndate
ORDER BY Receiptdate )s
OUTER APPLY(SELECT TOP 1 Shipdate
FROM dbo.ESNShip s with (nolock)
WHERE ESN = p.ESN
AND Shipdate > p.Returndate
ORDER BY Shipdate)e
Where p.returndate > '2012-11-01'
and p.ESN in ('268435459401659246','268435458814622954','270113179507864837')


Thanks,

JOV

jovillanuev
Junior Poster in Training
76 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

You have an extra open-parenthesis on line 3. Or, depending on what you mean in your query, a missing close-parenthesis at the end of line 12.

Also, just for clarity's sake, you may want to rethink the over-used alias "s" you use in lines 4, 7 and 9. You could use it in one place but not all three...it's confusing.

BitBlt
Master Poster
711 posts since Feb 2011
Reputation Points: 367
Solved Threads: 109
 

Yes BItbit. I got already the Error.
Sorry for my late reply.

I have lacking 1 Open Parenthesis in line 12. it should be e).

for aliasis, i should use different aliasis per line that you mention.?

jovillanuev
Junior Poster in Training
76 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

Glad to hear you found the error.

As far as the alias change, it is not actually "necessary". Your query will run fine without that change. It was just a suggestion to avoid potential confusion among the various different scopes of query and "apply".

BitBlt
Master Poster
711 posts since Feb 2011
Reputation Points: 367
Solved Threads: 109
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You