CREATE PROCEDURE usp_MyStored Proc ( @Parameter1 int = NULL, @Parameter 2 int = NULL @Parameter 3 int = NULL ) AS .....Calls:
EXEC usp_MyStoredProc 1, 2, 3; --You are passing in 3 values by index. There are three parameters so life is good. EXEC usp_MyStoredProc NULL, 2, 3; --You only want to pass in Parameter2 and Parameter3, but you need a filler for the first parameter since this is passing in parameters by index EXEC usp_MyStoredProc @Parameter2 = 2, @Parameter3 = 3; --You only want to pass in Parameter2 and Parameter3, and since we are using named parameters the Stored Procedure knows what goes where.>How do I create an update procedure that works the same way? I want to pass only the parameters for the changed columns.
>>... >>EXEC bm_GetClients NULL, @ClientKey >>--or >>... >>SET @CompanyKey = NULL >>EXEC bm_GetClients @CompanyKey, @ClientKey >> >>>>
>>EXEC bm_GetClients @ClientKey = @ClientKey
>>
>>>>> >>>SET ANSI_NULLS ON >>>GO >>>SET QUOTED_IDENTIFIER ON >>>GO >>> >>>CREATE PROCEDURE bm_GetClients >>> @CompanyKey INT = NULL, >>> @ClientKey INT = NULL >>> >>>AS >>>BEGIN >>> >>> SELECT * >>> FROM bm_Clients >>> WHERE (CompanyKey = @CompanyKey OR @CompanyKey IS NULL) AND >>> (ClientKey = @ClientKey OR @ClientKey IS NULL) >>>END >>>>>>
>>>DECLARE @CompanyKey INT >>>DECLARE @ClientKey INT >>>SET @CompanyKey = 2 >>>SET @ClientKey = 5 >>>EXEC bm_GetClients @CompanyKey = @CompanyKey, @ClientKey = @ClientKey >>>>>>