No Support for OVER in MS SQL Server 2005?

后端 未结 4 1855
我寻月下人不归
我寻月下人不归 2020-12-02 01:21

OVERI am getting an error when trying to run a query in MS SQL Server Management Studio. We use MS SQL Server 2005 on a windows 2003 server.

Here is the query:

相关标签:
4条回答
  • 2020-12-02 01:52

    The documentation for SQL Server 2005 says that OVER is certainly supported.

    The problem is that the editor window doesn't support it. See if you can close all the panes other than SQL and results view to make the error go away.

    0 讨论(0)
  • 2020-12-02 01:58

    Check the compatibility level on the particular database

    There is some more detail @ http://msdn.microsoft.com/en-us/library/ms178653(v=SQL.90).aspx

    If the compatibility level is less than 90, then new features, like the OVER clause, available only in SQL 2005, are turned off.

    0 讨论(0)
  • 2020-12-02 02:04

    Have you tried prepending a semicolon in front of your With statement? (e.g. ;With q As)


    Some general notes:

    1. You must run this in a query not the designer. It sounds like you have fixed that.
    2. Enumerate the columns instead of using *. I.e., in the example below replace Col1, Col2 with the actual columns you want prefixed by the table from whence they came.
    3. Put use DatabaseName at the top of your script followed by a line break, followed by GO, followed by another line-break.
    4. If the only statement prior to the With statement is the GO between your use statement and the query, then no semicolon is necessary since it is the first statement in the batch.

    use DatabaseName
    GO
    WITH q AS
            (
            SELECT  TableName.Col1, TableName.Col2,...
                , ROW_NUMBER() OVER (PARTITION BY dbo.[1_MAIN - Contacts].Contact_ID 
                                                            ORDER BY dbo.[1_MAIN - Contacts].Contact_ID ) AS rn
            FROM dbo.[1_MAIN - Contacts]
                INNER JOIN dbo.Referral
                    ON dbo.[1_MAIN - Contacts].Contact_ID = dbo.Referral.Referral_ID
                INNER JOIN dbo.prov_training_records
                    ON dbo.[1_MAIN - Contacts].Contact_ID = dbo.prov_training_records.Contact_ID
                LEFT OUTER JOIN dbo.Resource_Center
                    ON dbo.[1_MAIN - Contacts].Contact_ID = dbo.Resource_Center.Contact_ID
                FULL OUTER JOIN dbo.Providers
                    ON dbo.[1_MAIN - Contacts].Contact_ID = dbo.Providers.Contact_ID
            )
    SELECT  *
    FROM    q
    

    0 讨论(0)
  • 2020-12-02 02:06

    The problem is that you are using the Query Designer GUI. Stop doing that. The Query Designer is rubbish. It's useless for any non-trivial query development. Type you queries in a Management Studio editor window.

    0 讨论(0)
提交回复
热议问题