Torna al Thread

CREATE PROCEDURE [dbo].[Ricerca]( @cognome nvarchar(50), @causale int, @datainiziale DateTime, @datafinale DateTime, @cf nvarchar(16)) AS BEGIN DECLARE @sql nvarchar(2000) SET @sql ='SELECT u.Cognome, u.Nome, u.Via, u.Telefono,u.Comune,u.Cap,u.Provincia,u.Cf,b.Data_Versamento,b.Data_inserimento,b.IdOperatore,b.IdUtente,b.Note, c.Causale,c.Nr_CC from Utenti u Left Join Bollettino b on u.idUtenti = b.IdUtente INNER JOIN Causale c on b.IdCausale = c.IdCausale where b.Data_Versamento between' + @datainiziale + 'and' + @datafinale +'' IF(LTrim(@cognome) is not null) BEGIN SET @sql =' and u.Cognome = ' + @cognome + '' END IF(LTrim(@causale) is not null) BEGIN SET @sql= 'and c.Causale = ' + @causale + '' END IF(LTRim(@cf) is not null) BEGIN SET @sql=' and u.Cf = ' + @cf +'' END Exec(@sql) ENd
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5