Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 1 SP for different selections

Author  Topic 

richardlaw
Yak Posting Veteran

68 Posts

Posted - 2012-08-01 : 17:18:58
Hi

I've created a table that lists members of a gymnastics club. In the table is a bool/bit value for isGymnast and isCoach, as many of our coaches are also gymnasts.

I've like to create one SP to manage 3 selection types. Just gymnasts, just coaches, and everyone, but I'm not quite sure how to write it or what method to use?

When selecting just the gymnasts, I can't use 'isGymnast = 1 AND isCoach = 0' as this would discount gymnasts that are also coaches.

Any ideas?

Thanks as always

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-01 : 17:32:31
you can use like this
add a mode parameter @Mode and pass values like Gymnast,Coach

and make filter like

..
WHERE (@Mode!='Gymnast' OR isGymnast=1)
AND (@Mode !='coach' OR isCoach=1)



see

http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

richardlaw
Yak Posting Veteran

68 Posts

Posted - 2012-08-01 : 17:37:11
Great, thanks. I'll try that out.
Go to Top of Page
   

- Advertisement -