小编典典

基于存储过程参数的条件where子句?

sql

我有一个带参数的SQL Server 2005存储proc :@includeClosedProjects

WHERE我想根据此参数控制一个子句。

create proc sel_projects
(@incClosedRel int = 1)
as

SELECT projectId, projectName
FROM project
WHERE CompletionStatusCID NOT IN (34, 35) <-- controlled by @incClosedRel

我想获取所有项目(不包括where子句),何时@incClosedRel =1。否则,请包含where子句。


阅读 164

收藏
2021-04-22

共1个答案

小编典典

SELECT projectId, projectName
FROM project
WHERE CompletionStatusCID NOT IN (34, 35) 
    Or @incClosedRel = 1
2021-04-22