|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Dynamic AND!I am wanting to add an optional and statement to a query. Not quite sure how to go about it. My attempt so far: SELECT bsc_assmnt_area_id, name, parent_id FROM bsc_assmnt_areas WHERE parent_id = @pid CASE WHEN parent_id = 0 Then And mine_id = @mid END Would appreciate some insight on how to do this? Cheers, Adam Something like this:
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=469 -- Show quote2004 and 2005 Microsoft MVP C# Robbe Morris http://www.masterado.net Earn $$$ money answering .NET Framework messageboard posts at EggHeadCafe.com. http://www.eggheadcafe.com/forums/merit.asp "Adam Knight" <d**@brightidea.com.au> wrote in message news:%23g8Px69kFHA.3436@tk2msftngp13.phx.gbl... > Hi all, > > I am wanting to add an optional and statement to a query. > Not quite sure how to go about it. > > My attempt so far: > SELECT > > bsc_assmnt_area_id, name, parent_id > > FROM > > bsc_assmnt_areas > > WHERE > > parent_id = @pid > > CASE > > WHEN parent_id = 0 Then And mine_id = @mid > > END > > Would appreciate some insight on how to do this? > > Cheers, > > Adam > > SELECT bsc_assmnt_area_id, name, parent_id
FROM bsc_assmnt_areas WHERE parent_id = @pid AND mine_id = (CASE WHEN parent_id = 0 THEN @mid ELSE mine_id END) is one way of doing it.
http://www.sommarskog.se/dyn-search.html
Show quote "Adam Knight" <d**@brightidea.com.au> wrote in message
news:%23g8Px69kFHA.3436@tk2msftngp13.phx.gbl... > Hi all, > > I am wanting to add an optional and statement to a query. > Not quite sure how to go about it. > > My attempt so far: > SELECT > > bsc_assmnt_area_id, name, parent_id > > FROM > > bsc_assmnt_areas > > WHERE > > parent_id = @pid > > CASE > > WHEN parent_id = 0 Then And mine_id = @mid > > END > > Would appreciate some insight on how to do this? > > Cheers, > > Adam > > |
|||||||||||||||||||||||