SQL Server 2008 - Conditional Query

前端 未结 6 1505
说谎
说谎 2020-12-10 19:09

SQL is not one of my strong suits. I have a SQL Server 2008 database. This database has a stored procedure that takes in eight int parameters. For the sake of keeping this q

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 19:55

    There is NOT an elegant way - all ways suck.

    WHERE @isActive == -1 OR isActive = @isActive

    is basically the only way - but even then you please make sure that the query plan is reevaluated every time, otherwise most queries will use the wrong query plan.

    THis is a classical case where stored procedures are bad. Querying should IMHO not be done using stored procedures at all since modern times - which started about 15 years ago when someone was smart enough to write the first ORM.

提交回复
热议问题