Optional parameter in SQL server

前端 未结 2 1467
我在风中等你
我在风中等你 2021-01-11 18:50

I have a user defined function which is used in many stored procedures which will return me some value. If it possible for me to add a new optional parameter to the same.

2条回答
  •  不要未来只要你来
    2021-01-11 19:21

    I think the easiest way is to make a stored procedure CalculateAverageForUserAndType(int userid ,type NVARCHAR(10)) Put your original code inside the new procedure. Then change CalculateAverageForUser to

    dbo.CalculateAverageForUser(int userid)
    AS
    BEGIN
        EXEC CalculateAverageForUserAndType userid, NULL
    
    END
    

    This way you can slowly migrate to your new stored procedure and your old one still works.

提交回复
热议问题