简单的存储过程,执行一条count语句,就是根据参数来选择不同的where条件:create procedure U_QuestionListCount
(
@id int
)
as
select count([QuestionId]) from [U_Question] where (
case @id
when 0 then [IsOver]=0
when 1 then [IsOver]=1
when 2 then [IsOver]=1 and [IsGood]=1
else [IsOver]=0
end
)
GO错误提示:when...case语法错误,望给予帮助,不甚感激!
(
@id int
)
as
select count([QuestionId]) from [U_Question] where (
case @id
when 0 then [IsOver]=0
when 1 then [IsOver]=1
when 2 then [IsOver]=1 and [IsGood]=1
else [IsOver]=0
end
)
GO错误提示:when...case语法错误,望给予帮助,不甚感激!
解决方案 »
- AJax.NET AJax控件问题
- post图片和数据
- 一个很奇怪的Session问题
- 如何将ASPX页面中的代码写如后置的CS文件中?
- ASP.net用socket向winform发送消息,第一次可以,接着就不行了!!求教
- 怎么才能修改xml中节点的名字呢,而不是节点中的值,如<USA url="usa.com"><state>New York</state></USA>要修改节点名字 USA为CHN 怎么做
- 救急!!浏览页面出错!
- ASP.NET 中如何使用netmeeting(最好是嵌入到web中)
- 为什么这样的语句在xsl中是错误的?
- 动态生成的控件的事件响应怎样解决(50分!)
- 各位高人进来看看
- 在VS2005裡面將DataGrid中的數據導入到Excel中,供用戶下載,編輯。
create procedure U_QuestionListCount
(
@id int
)
as
declare @whereStr varchar(100)
select @whereStr =
case @id
when 0 then '[IsOver]=0'
when 1 then '[IsOver]=1'
when 2 then '[IsOver]=1 and [IsGood]=1'
else '[IsOver]=0'
end
execute('select count([QuestionId]) from [U_Question] where '+@whereStr)
GO
LZ你那样是 SELECT 语句中使用CASE啊当然可以啦
(
@id int
)
as
select count([QuestionId]) from [U_Question] where (
case @id
when 0 then 0
when 1 then 1
when 2 then 1
else 0
end as [IsOver] and [IsGood]=1
)
GO