Wednesday, March 7, 2012

Help Needed

hi,
i have table with following feilds

ProgramId ProgramType AccountName ProgramName ProgramBudget ProgramStatus

I need to write a search query to generate a report where search criteria will be (ProgramType=1,2,3 or All of above),(AccountName=a,b,c or All of above),(ProgramStatus=y,n or all of above)

any clues,

thnx in advance
sudheer.hi,

try something like this:

declare @.PID int, @.PTY int
set @.PID=null -- will search "all"
set @.PID=2 -- will search for ProgramID=2 etc
:
:
select *
from <tablename>
where ((@.PID is null) or (ProgramID=@.PID)) and
((@.PTY is null) or (ProgramType=@.PTY))
:

markus

No comments:

Post a Comment