0

我有一个奇怪的行为,我执行一个运行查询的方法。它适用于本地主机,但在质量环境上失败。查询和错误如下:

WITH t AS 
(
    SELECT
        *,
        ROW_NUMBER() OVER(PARTITION BY matricola  ORDER BY esercizio DESC, cod_valutazione, valutaz_sintetica, matricola, FigureOrder) AS RowN 
    FROM 
        (SELECT DISTINCT 
            '' AS pdf,
            Vm.NomeManager + ' ' + Vm.CognomeManager AS valutatore,
            vpd.ESERCIZIO AS esercizio,
            vpd.cod_valutazione,
            Vm.NomeValutato +' ' + Vm.CognomeValutato AS valutato,
            vpd.matricola,
            valutaz_sintetica,
            vpd.COD_STATO AS stato_scheda,
            vpd.VALUTAZIONE_RANKING_SINTETICA,
            vvv.COD_FIGURA,
            CASE
                WHEN COD_FIGURA = 'OWNG' THEN 0
                WHEN COD_FIGURA = 'VAL1' THEN 1
                WHEN COD_FIGURA = 'OWN' THEN 2
            END AS FigureOrder      
        FROM
            View_SchedePerDistribuzione vpd
            INNER JOIN RL_VALUTAZIONE_VALUTATI_VALUTATORI vvv ON vpd.COD_VALUTAZIONE = vvv.COD_VALUTAZIONE AND vpd.MATRICOLA = vvv.MATRICOLA_VALUTATO 
            INNER JOIN ValutatiManager  Vm ON vpd.MATRICOLA = Vm.MatricolaVAlutato AND vpd.COD_VALUTAZIONE = Vm.COD_VALUTAZIONE
        WHERE 
            vpd.cod_valutazione='PA_SCI_11-12_test' AND 
            vpd.cod_stato='PROP' AND 
            chiusa = 0 AND 
            valutaz_sintetica <> '' AND 
            VVV.COD_FIGURA IN ('VAL1', 'OWN', 'OWNG') AND 
            VVV.Matricola = '06000013' 
        ) AS tab) 

        SELECT * 
          FROM t
         WHERE RowN = 1
         ORDER BY esercizio DESC, cod_valutazione, valutaz_sintetica, matricola, FigureOrder

这是错误:

        nnString=Provider=SQLOLEDB;Data Sourcexxx;Initial Catalog=xxx;Persist Security Info=True;User ID=xxx;Password='xxx';Connect Timeout=xx System.Data.OleDb.OleDbException (0x80040E14): 
        Incorrect syntax near the keyword 'with'.     
        at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)     
        at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)     
        at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)     
        at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)     
        at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)     
        at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)     
        at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)     
        at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)     
        at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)     
        at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)     
        at valDipLibrary.utility.getQuery(String qry, OleDbTransaction SqlTrn, String ConnString, Boolean fromPool, Boolean logReq, Int32 startRecord, Int32 maxRecord)     
        at valDipLibrary.utility.getQuery(String qry, OleDbTransaction SqlTrn, String ConnString, Boolean fromPool, Boolean logReq, Int32 startRecord, Int32 maxRecord)

更多信息:

如果我在我的 SSMS 上运行查询,它就可以工作。如果我在质量服务器的 SSMS 上运行查询,它就可以工作。

仅当我运行执行查询的方法时它才起作用。

你能帮助我吗?

4

2 回答 2

1

我猜质量服务器的版本低于 2005。因为从 2005 版本开始支持 CTE

于 2012-07-27T08:13:21.833 回答
1

尝试在单词前加分号 with

IE:

;WITH t AS  
( 
    SELECT 
    ...
于 2012-07-27T08:16:05.657 回答