Result_page da oracle a sql server

giovedì 13 dicembre 2012 - 17.12
Tag Elenco Tags  SQL Server 2008 R2  |  SQL Server 2008  |  SQL Server 2005  |  SQL Server Express  |  Oracle 11g  |  Oracle 10g  |  Oracle 9g

gsflash80 Profilo | Junior Member

ciao a tutti, sto cercando di tradurre lo script da oracle a sql server:

ORACLE

select * from ( select /*+ FIRST_ROWS(n) */ a.*, ROWNUM rnum from ( SELECT /*+ index (A INDX_TRASM3) */ ROW_NUMBER() OVER(ORDER BY a.dta_invio DESC) AS RN, a.system_id, a.id_ruolo_in_uo as ruolo_system_id, g.var_cod_rubrica as ruolo_mittente, a.id_people as user_system_id, p.full_name as user_id, a.cha_tipo_oggetto, a.id_profile, a.id_project, dta_invio, a.var_note_generali, a.cha_salvata_con_cessione, g.VAR_DESC_CORR as ruolo, p.user_id as us_id, a.id_people_delegato FROM dpa_trasmissione a INNER JOIN dpa_trasm_singola ts on a.system_id = ts.id_trasmissione INNER JOIN dpa_trasm_utente tu ON ts.system_id = tu.id_trasm_singola INNER JOIN people p ON a.id_people = p.system_id INNER JOIN dpa_corr_globali g ON a.id_ruolo_in_uo = g.system_id WHERE filters ) a where ROWNUM <= endRow ) where rnum >= startRow;

e sto provando in SQL SERVER:
CREATE PROCEDURE Risultato_Page_New_Rowcount ( @startRowIndex int, @maximumRows int ) AS DECLARE @TempItems TABLE ( ID int IDENTITY, EmployeeID int ) DECLARE @maxRow int SET @maxRow = (@startRowIndex + @maximumRows) - 1 SET ROWCOUNT @maxRow INSERT INTO @TempItems (EmployeeID) SELECT EmployeeID FROM Employees ORDER BY EmployeeID SET ROWCOUNT @maximumRows SELECT /*+ index (A INDX_TRASM3) */ ROW_NUMBER() OVER(ORDER BY a.dta_invio DESC) AS RN, a.system_id, a.id_ruolo_in_uo as ruolo_system_id, g.var_cod_rubrica as ruolo_mittente, a.id_people as user_system_id, p.full_name as user_id, a.cha_tipo_oggetto, a.id_profile, a.id_project, dta_invio, a.var_note_generali, a.cha_salvata_con_cessione, g.VAR_DESC_CORR as ruolo, p.user_id as us_id, a.id_people_delegato FROM dpa_trasmissione a INNER JOIN dpa_trasm_singola ts on a.system_id = ts.id_trasmissione INNER JOIN dpa_trasm_utente tu ON ts.system_id = tu.id_trasm_singola INNER JOIN people p ON a.id_people = p.system_id INNER JOIN dpa_corr_globali g ON a.id_ruolo_in_uo = g.system_id WHERE ID >= @startRowIndex SET ROWCOUNT 0 GO

però non funziona, dove avrei sbagliato? grazie
----

..:: GSFLASH ::..
http://www.gsflash.it
http://blogs.dotnethell.it/gabrieleserpi/
MCTS - ACP - OCP - ECDL - ACSP
Ubuntu 11.04/OpenSuse 10.3
Vista Seven/MacOSX SnowLeopard

HolidaySoft.it Profilo | Junior Member

Ciao,
anche in sql server esiste la funzione ROW_NUMBER(), quindi il passaggio dovrebbe essere indolore. Io l'ho tradotta in questo modo. Prova a vedere:

select a.*, RN rnum from ( SELECT ROW_NUMBER() OVER(ORDER BY a.dta_invio DESC) AS RN, a.system_id, a.id_ruolo_in_uo as ruolo_system_id, g.var_cod_rubrica as ruolo_mittente, a.id_people as user_system_id, p.full_name as user_id, a.cha_tipo_oggetto, a.id_profile, a.id_project, dta_invio, a.var_note_generali, a.cha_salvata_con_cessione, g.VAR_DESC_CORR as ruolo, p.user_id as us_id, a.id_people_delegato FROM dpa_trasmissione a INNER JOIN dpa_trasm_singola ts on a.system_id = ts.id_trasmissione INNER JOIN dpa_trasm_utente tu ON ts.system_id = tu.id_trasm_singola INNER JOIN people p ON a.id_people = p.system_id INNER JOIN dpa_corr_globali g ON a.id_ruolo_in_uo = g.system_id WHERE /* filters*/ ) a where RN between startRow and endRow
A quick solution is a shortcut to troubleshooting
http://www.HolidaySoft.it
http://www.GarganoSapori.it
http://www.osteriaoristorante.it

gsflash80 Profilo | Junior Member

grazie per la risposta

poi senza mettere @startRow and @endRow

errore:
Messaggio 102, livello 15, stato 1, riga 26
Incorrect syntax near ')'.
----

..:: GSFLASH ::..
http://www.gsflash.it
http://blogs.dotnethell.it/gabrieleserpi/
MCTS - ACP - OCP - ECDL - ACSP
Ubuntu 11.04/OpenSuse 10.3
Vista Seven/MacOSX SnowLeopard

gsflash80 Profilo | Junior Member

grazie per la risposta

poi senza mettere @startRow and @endRow?

errore:
Messaggio 102, livello 15, stato 1, riga 26
Incorrect syntax near ')'.
----

..:: GSFLASH ::..
http://www.gsflash.it
http://blogs.dotnethell.it/gabrieleserpi/
MCTS - ACP - OCP - ECDL - ACSP
Ubuntu 11.04/OpenSuse 10.3
Vista Seven/MacOSX SnowLeopard

HolidaySoft.it Profilo | Junior Member

ok, ovviamente dove c'è scritto filters immagino che dovevi mettere dei filtri/condizioni... altrimenti puoi provarla così:

select a.*, RN rnum from ( SELECT ROW_NUMBER() OVER(ORDER BY a.dta_invio DESC) AS RN, a.system_id, a.id_ruolo_in_uo as ruolo_system_id, g.var_cod_rubrica as ruolo_mittente, a.id_people as user_system_id, p.full_name as user_id, a.cha_tipo_oggetto, a.id_profile, a.id_project, dta_invio, a.var_note_generali, a.cha_salvata_con_cessione, g.VAR_DESC_CORR as ruolo, p.user_id as us_id, a.id_people_delegato FROM dpa_trasmissione a INNER JOIN dpa_trasm_singola ts on a.system_id = ts.id_trasmissione INNER JOIN dpa_trasm_utente tu ON ts.system_id = tu.id_trasm_singola INNER JOIN people p ON a.id_people = p.system_id INNER JOIN dpa_corr_globali g ON a.id_ruolo_in_uo = g.system_id -- WHERE /* filters*/ ) a where RN between startRow and endRow

ho tolto la WHERE tramite --
oppure elimina proprio la riga
WHERE /* filters*/
A quick solution is a shortcut to troubleshooting
http://www.HolidaySoft.it
http://www.GarganoSapori.it
http://www.osteriaoristorante.it
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5