基于存储过程参数的条件

基于存储过程参数的条件

本文介绍了基于存储过程参数的条件 where 子句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a SQL Server 2005 stored proc that takes a parameter: @includeClosedProjects.

我想根据这个参数控制一个 WHERE 子句.

There's a WHERE clause that I want to control based on this param.

create proc sel_projects
(@incClosedRel int = 1)
as

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

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

I want to get all projects (exclude the where clause), when @incClosedRel =1.Otherwise, include the where clause.

推荐答案

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

这篇关于基于存储过程参数的条件 where 子句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 08:15