optional parameters in SQL Server stored proc?

前端 未结 3 819
长发绾君心
长发绾君心 2020-11-30 03:20

I\'m writing some stored procs in SQL Server 2008, and wondered if the concept of optional input parameters is possible here?

I suppose I could always pass in NULL

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 04:10

    Yes, it is. Declare parameter as so:

    @Sort varchar(50) = NULL
    

    Now you don't even have to pass the parameter in. It will default to NULL (or whatever you choose to default to).

提交回复
热议问题