CREATE PROCEDURE [dbo].[sp_getLastSavedUserModel] @pIdReportModello as int, @pUtente as varchar(13) = null, @pTpReport as int AS BEGIN if @pUtente is not null SELECT TOP (1) IdReport, Nome, Descrizione FROM Report WHERE (Utente = @pUtente) AND (Nome NOT LIKE '%LAST USED CONFIG%') AND (IdReportModello = @pIdReportModello) AND (TpReport = @pTpReport) ORDER BY DtCreazione DESC else SELECT TOP (1) IdReport, Nome, Descrizione FROM Report WHERE Nome NOT LIKE '%LAST USED CONFIG%' AND (IdReportModello = @pIdReportModello) AND (TpReport = @pTpReport) ORDER BY DtCreazione DESC END