Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have 3 textbox and 2 dropdownlist and one linkbutton for search in a page and i want to search one by one of these controls on click event of link button and these query written in a single stored procedure. Plz help me

OP added:
how to create one stored procedure for searching. for ex-: I want to search to customerid, customername, Salesname, Soapname, Address.......

Thanks
Shashank
Posted
Updated 29-Oct-11 2:02am
v2

IN This procedure you can search from any control i have 4 dropdown and two textbox for search you can set your parameter .In this procedure tarif,fabricant,nivel1,nivel2 is dropdown value and other two is textbox value.
in this procedure first  we add our normal query in "@SqlQuery" when query assign in this variable.we add query on the basis of search criteria for EX.
IF (@Tarifa <> 'Select') 
SET @SqlQuery= @SqlQuery + ' AND (Tarifa.Tarifa = ''' + @Tarifa +''')'
in this syntax @SqlQuery contain previos query and from this expression "AND (Tarifa.Tarifa = ''' + @Tarifa +''')'" we add condition and it will work fine


SQL
CREATE PROCEDURE [dbo].[SP_FilterPriceRule]
		@Tarifa nvarchar(50),@Fabricante varchar(20), @Nivel1 varchar(50), @Nivel2 varchar(50),
		@PorSobreCoste decimal(18,0) = NULL, @PorcentajeDescuento decimal(18,0) = NULL
AS
  DECLARE @SqlQuery AS nvarchar(max)
  DECLARE @SqlQuery1 AS nvarchar(max)
  DECLARE @FinalQuery AS nvarchar(max)
  
  print cast(@PorSobreCoste as varchar(10))
  SET @SqlQuery='SELECT ReglaTarificacion.Id,convert(varchar,Tarifa.IdTarifa) +''-''+ Tarifa.Tarifa AS Tarifa, Fabricante.Descripcion AS Fabricante, Nivel1.Descripcion AS Nivel1, Nivel2.Descripcion AS Nivel2, ReglaTarificacion.PorSobreCoste AS PorSobreCoste, 
                      ReglaTarificacion.PorcentajeDescuento AS PorcentajeDescuento, ReglaTarificacion.OrdenEjecucion
			FROM      ReglaTarificacion LEFT JOIN
                      Tarifa ON ReglaTarificacion.Idtarifa = Tarifa.IdTarifa LEFT JOIN
                      Fabricante ON ReglaTarificacion.CodFab = Fabricante.Codfab LEFT JOIN
                      Nivel2 ON ReglaTarificacion.IdNivel2 = Nivel2.Codigo_nivel2 LEFT JOIN
                      Nivel1 ON Nivel2.Codigo_nivel1 = Nivel1.Codigo_nivel1
                      where (1=1)'
                      
  
   IF (@Tarifa <> 'Select') SET @SqlQuery= @SqlQuery + ' AND (Tarifa.Tarifa = ''' + @Tarifa +''')'
		
   IF (@Fabricante <>'Select') 	SET @SqlQuery=@SqlQuery + ' AND (Fabricante.Descripcion = ''' + @Fabricante +''')'
		
   IF (@Nivel1 <>'Select') SET @SqlQuery=@SqlQuery + ' AND (Nivel1.Descripcion = ''' + @Nivel1 +''')'
		
   IF (@Nivel2 <>'Select') SET @SqlQuery=@SqlQuery + ' AND (Nivel2.Descripcion = ''' + @Nivel2 +''')'
		
	IF (@PorSobreCoste IS NOT NULL )
	begin
		SET @SqlQuery=@SqlQuery + ' AND (ReglaTarificacion.PorSobreCoste = '+ cast( @PorSobreCoste as varchar(10)) +')' 	
	end
		
	IF (@PorcentajeDescuento IS NOT NULL)
	BEGIN
		SET @SqlQuery=@SqlQuery + ' AND (ReglaTarificacion.PorcentajeDescuento = '+ cast( @PorcentajeDescuento as varchar(10)) +')' 		
	END		
	SET @SqlQuery= @SqlQuery + ' ORDER BY ReglaTarificacion.OrdenEjecucion'
	print @SqlQuery
   	exec(@SqlQuery)


if this procedure usefull for you then please Vote 
 
Share this answer
 
v3
Google returned about 14,000,000 hits[^] that you might find useful.

We will be happy to help you with actual technical problems, but you'll have to make an effort first ...

Best regards
Espen Harlinn
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900