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

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.

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.?

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".