SQLTeam.com | Weblogs | Forums

Search product by multiple select category for e-comm project just like Jabong


#1

how to search product by multiple select category in sql server

how to make procedure in sql server.
plz advice me


#2

Use the "in" operator.

select ...
  from ...
 where category in ('Software','Hardware')
;

#3

hi bitsmed,

select ...
from ...
where category in ('Software','Hardware')
it works but when u pass a variable then problem

select ...
from ...
where category in (@ctgrName)

not working


#4

You could handle this in your program where you dynamically generate the query, or you could do a dynamic query on the fly.

Or maybe:

declare @ctgrName varchar(200)=',Hardware,Software,';
select ...
  from ...
 where @ctgrName like '%,'+category+',%'
;

or if you have commas in your category values:

declare @ctgrName varchar(200)='¤Hardware¤Software¤';
select ...
  from ...
 where @ctgrName like '%¤'+category+'¤%'
;


#5

thnx dost


#6

Hello sir
Goodevening.

error when category not select

how to do best idea ???

plz help me sir ?


#7

For this to work, you must always declare @ctgrName.
If you don't assign a value to it, result will be no rows.