Torna al Thread

ALTER PROCEDURE [dbo].[FE_recupera_interventi] @tipoIntervento int, @stato varchar(10), @richiesta_dal varchar(10), @richiesta_al varchar(10), @user_id int, @idTecnico varchar(10), @idRichiedente varchar(10), @pageIndex int, @user_tecnico int AS declare @stringa nvarchar(4000) declare @stringa2 nvarchar(4000) declare @pagesize int set @pagesize = 10 declare @ParmDefinition nvarchar(4000) BEGIN set @ParmDefinition=N'@tipoIntervento int, @stato varchar(10), @richiesta_dal varchar(10), @richiesta_al varchar(10), @user_id int, @idTecnico varchar(10), @idRichiedente varchar(10), @pageIndex int, @pagesize int' set @stringa = 'select top(@pagesize) I.idIntervento, Urich.nome as nome_richiedente, Urich.cognome as cognome_richiedente, I.dataRichiesta as dataRichiesta, tec.nome as nome_tecnico, tec.cognome as cognome_tecnico, I.stato, I.problema from interventi I left join utenti Urich on I.idRichiedente=Urich.id_utenti left join utenti tec on I.idTecnico=tec.id_utenti where tipoIntervento = @tipoIntervento ' if @stato <> '' begin set @stringa = @stringa + ' and I.stato = @stato ' end else if (@richiesta_dal <> '') and (@richiesta_al <> '') begin set @stringa = @stringa + ' and I.dataRichiesta Between @richiesta_dal and @richiesta_al ' end else if @idTecnico <> '' begin set @stringa = @stringa + ' and I.idTecnico = cast(@idTecnico as int) ' end else if @idRichiedente <> '' begin set @stringa = @stringa + ' and I.idRichiedente = cast(@idRichiedente as int) ' end set @stringa = @stringa + ' and I.idIntervento not in (' set @stringa2 = 'select top(@pagesize * @pageindex) I.idIntervento from interventi I left join utenti Urich on I.idRichiedente=Urich.id_utenti left join utenti tec on I.idTecnico=tec.id_utenti where tipoIntervento = @tipoIntervento ' if @stato <> '' begin set @stringa2 = @stringa2 + ' and I.stato = @stato ' end else if (@richiesta_dal <> '') and (@richiesta_al <> '') begin set @stringa2 = @stringa2 + ' and I.dataRichiesta Between @richiesta_dal and @richiesta_al ' end else if @idTecnico <> '' begin set @stringa2 = @stringa2 + ' and I.idTecnico = cast(@idTecnico as int) ' end else if @idRichiedente <> '' begin set @stringa2 = @stringa2 + ' and I.idRichiedente = cast(@idRichiedente as int) ' end set @stringa2 = @stringa2 + ' order by I.idIntervento ASC)' set @stringa = @stringa + @stringa2 set @stringa = @stringa + ' order by I.idIntervento ASC' execute sp_executesql @stringa, @ParmDefinition, @tipoIntervento=@tipoIntervento, @stato=@stato, @richiesta_dal=@richiesta_dal, @richiesta_al=@richiesta_al, @user_id=@user_id, @idTecnico=@idTecnico, @idRichiedente=@idRichiedente, @pageIndex=@pageIndex, @pagesize=@pagesize;
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5