Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stored Proc Problem
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01394196
Message ID:
01394200
Vues:
50
>This stored proc takes 2 optional params.
>
>
>
>CREATE PROCEDURE bm_GetClients
>	@CompanyKey		INT = NULL,
>	@ClientKey		INT = NULL
>
>AS
>BEGIN
>
>	SELECT *
>		FROM bm_Clients
>		WHERE CompanyKey = ISNULL(@CompanyKey, CompanyKey) OR
>			  ClientKey = ISNULL(@ClientKey, ClientKey)
>
>END
>
>
>I want to pass either, both, or none. I'm running it like this:
>
>
>DECLARE @CompanyKey	INT
>DECLARE @ClientKey	INT
>SET @CompanyKey = 2
>SET @ClientKey = 5
>
>EXEC bm_GetClients
>EXEC bm_GetClients @ClientKey
>EXEC bm_GetClients @CompanyKey, @ClientKey 
>EXEC bm_GetClients @CompanyKey
>
>
>In all cases I'm getting back all records

Change:
WHERE CompanyKey = ISNULL(@CompanyKey, CompanyKey) OR
      ClientKey  = ISNULL(@ClientKey, ClientKey)
to
WHERE CompanyKey = ISNULL(@CompanyKey, CompanyKey) AND
      ClientKey  = ISNULL(@ClientKey, ClientKey)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform