Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can I use the case statement ?
Message
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Can I use the case statement ?
Divers
Thread ID:
00596736
Message ID:
00596736
Vues:
50
I'm wondering if I can use the case statement in a stored procedure for the where clause.

Example: In my vfp form, I want to let the user decide which field to filter:

I have a combo box for User, and a combo box for action. Each combo box will have the available section with ALL being an option also.

I was wondering if I could create one stored procedure that was something like
CREATE PROCEDURE ct_UserAuditListing 
@tiUserID int,
@tcAction varchar(30)

--tiUserID=0 we want all users
--tcAction="ALL" we want all actions

as

select * from coAudit
case 
	when @tiUserid>0 and @tcAction='ALL' then where userid=@tiUserID 
	when @tiUserID>0  then where userid=@tiUserID and actiontype=@tcAction 
	when @tiUserID=0 and @tcAction<>'ALL' then where actiontype=@tcAction 
Obviously, the code above doesn't work, but is there a way to make it work or do I have to make a seperate stored procedure for each flavor of the query

Kirk
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform