-1

Very disappointing, but some how not able to crack why I am getting this error?

SELECT 1  
FROM dbo.[Call] C WITH (nolock) 
OUTER APPLY
      (
        SELECT TOP 1 LastModifiedDateTime,LastModifiedUser,Note 
        FROM dbo.Note 
        WHERE dbo.Note.CallID = C.Call
        ORDER BY dbo.Note.LastModifiedDateTime DESC
      ) LatestNote  

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'OUTER'.

Msg 170, Level 15, State 1, Line 9
Line 9: Incorrect syntax near 'LatestNote'.

shA.t
  • 16,580
  • 5
  • 54
  • 111
AK47
  • 3,707
  • 3
  • 17
  • 36
  • is it because of ORDER BY clause? – Mukund Oct 15 '15 at 09:07
  • Nope, it is saying incorrect near 'OUTER' also. – AK47 Oct 15 '15 at 09:11
  • Your query works fine (or at least without syntax errors) on SQL Server 2008R2. Are you absolutely sure you're running against the server version you think you are? What's the output from `SELECT @@VERSION`? – Matt Gibson Oct 15 '15 at 09:22
  • IMO, Your current query has not any error !? - I suggest you to use SQLFiddle.com and make a sample data that gives error ;). – shA.t Oct 15 '15 at 09:22
  • 1
    @MattGibson, in about box it shows SQL Server 2008 R2. But adter I ran @@VERSION is say "Microsoft SQL Server 2000 - 8.00.760 (Intel X86) Dec 17 2002 14:22:05 Copyright (c) 1988-2003 Microsoft Corporation Enterprise Edition on Windows NT 5.0 (Build 2195: Service Pack 4) ". I got issue. It might be because of compatibility. Thanks. – AK47 Oct 15 '15 at 09:33
  • As far as i am concern you cannot use TOP caluse in sub query. Hence the error. – Ankit Bajpai Oct 15 '15 at 09:38
  • @AnkitBajpai No, you can use `TOP` and `ORDER BY` in `CROSS APPLY`. [When should I use Cross Apply over Inner Join?](http://stackoverflow.com/questions/1139160/when-should-i-use-cross-apply-over-inner-join) – Evaldas Buinauskas Oct 15 '15 at 09:41
  • 2
    Yup, that's the problem. `APPLY` simply isn't available in SQL Server 2000. It was added about a decade ago. If you're using the "About" box on your client tools, that's not the same as the server version -- you can connect to a SQL Server 2000 server from the 2016 client tools, but it's the *server* version that matters for running the actual SQL. (You should tag your posts with the *server* version you're using, not the version of the client tools.) – Matt Gibson Oct 15 '15 at 09:59

1 Answers1

1

After few help from comments, I found that Database was of 2000 , but I was accessing it from 2008 SSMS.

AK47
  • 3,707
  • 3
  • 17
  • 36
  • 1
    Bear in mind that Microsoft [terminated all support, including security updates, for SQL Server 2000 more than two years ago](http://blogs.msdn.com/b/sqlreleaseservices/archive/2013/04/08/end-of-extended-lifecycle-support-for-sql-server-2000-service-pack-4.aspx). It would definitely be a good idea to upgrade that server, if for no other reason than that you'll keep being sad that many, many new features like APPLY have been added over the last fifteen years that you can't use... – Matt Gibson Oct 15 '15 at 17:03