Stored Procedures CASE 用法错误
create PROCEDURE USP_GetDetail(@ObjectName nvarchar(50))
as
Begin
declare @type varchar(10)
select @type=[type] from sys.objects with(nolock) where name=@ObjectName
case @type
WHEN 'U' THEN
exec('select count(1) as 总行数 from ' + @ObjectName + ' with(nolock)')
exec('select top 100 * from ' + @ObjectName + ' with(nolock)')
WHEN 'P' THEN
exec('sp_helptext '+ @ObjectName)
WHEN 'FN' THEN
exec('sp_helptext '+ @ObjectName)
else
select '不明对象,不能取出对应信息.' as ErrorMessage
End
End
提示错误如下:

正确写法如下:
看看你知道问题错在哪里没有
create PROCEDURE USP_GetDetail(@ObjectName nvarchar(50))
as
Begin
declare @type varchar(10)
select @type=[type] from sys.objects with(nolock) where name=@ObjectName
declare @str nvarchar(100)
select @str = case @type
WHEN 'U' THEN
'select count(1) as 总行数 from ' + @ObjectName + ' with(nolock)' + ' '
+ 'select top 100 * from ' + @ObjectName + ' with(nolock)'
WHEN 'P' THEN
'sp_helptext '+ @ObjectName
WHEN 'FN' THEN
'sp_helptext '+ @ObjectName
else
'select '+ '''不明对象,不能取出对应信息.''' + ' as ErrorMessage'
End exec(@str)
End
Stored Procedures CASE 用法错误的更多相关文章
- Home / Python MySQL Tutorial / Calling MySQL Stored Procedures in Python Calling MySQL Stored Procedures in Python
f you are not familiar with MySQL stored procedures or want to review it as a refresher, you can fol ...
- sql case 用法总结
快下班了,抽点时间总结一下sql 的 case 用法. sql 里的case的作用: 用于计算条件列表的表达式,并返回可能的结果之一.sql 的case 类型于编程语言里的 if-esle if-el ...
- [MySQL] Stored Procedures 【转载】
Stored routines (procedures and functions) can be particularly useful in certain situations: When mu ...
- Good Practices to Write Stored Procedures in SQL Server
Reference to: http://www.c-sharpcorner.com/UploadFile/skumaar_mca/good-practices-to-write-the-stored ...
- An Introduction to Stored Procedures in MySQL 5
https://code.tutsplus.com/articles/an-introduction-to-stored-procedures-in-mysql-5--net-17843 MySQL ...
- Cursors in MySQL Stored Procedures
https://www.sitepoint.com/cursors-mysql-stored-procedures/ After my previous article on Stored Proce ...
- MySQL Error Handling in Stored Procedures 2
Summary: this tutorial shows you how to use MySQL handler to handle exceptions or errors encountered ...
- [转]How to: Execute Oracle Stored Procedures Returning RefCursors
本文转自:http://www.telerik.com/help/openaccess-orm/openaccess-tasks-oracle-execute-sp-result-set.html I ...
- SQL进阶随笔--case用法(一)
SQL进阶一整个是根据我看了pdf版本的整理以及自己的见解整理.后期也方便我自己查看和复习. CASE 表达式 CASE 表达式是从 SQL-92 标准开始被引入的.可能因为它是相对较新的技术,所以尽 ...
随机推荐
- Continuously Integrate
 Continuously Integrate David Bartlett THE Build AS A "Big BAng" EvEnT in project develop ...
- Android开发:LocationManager获取经纬度及定位过程(附demo)
在Android开发其中.常常须要用到定位功能,尤其是依赖于地理位置功能的应用.非常多人喜欢使用百度地图,高德地图提供的sdk.开放API,可是在只须要经纬度,或者城市,街道地址等信息.并不须要提供预 ...
- POJ2594 Treasure Exploration[DAG的最小可相交路径覆盖]
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8301 Accepted: 3 ...
- ubuntu 安装codeblocks
本文转载于:http://blog.csdn.net/i_fuqiang/article/details/9749225 1.安装gcc: sudo apt-get install build-ess ...
- iOS 跳转到Appstore的链接及二维码
1.应用内部跳转到Appstore 1.跳转到应用详情 [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"it ...
- 一阶 斜率 二阶 原函数的粗糙度 roughness
1 2 损失函数+惩罚函数 2阶导数
- vue如何做分页?
原创作品转载请注明出处 先来看一下效果图: 功能描述: 1. 点击页面序号跳转到相应页面: 2. 点击单左/单右,向后/向前跳转一个页面: 3. 点击双左/双右,直接跳转到最后一页/第一页: 3 ...
- MySql 三大知识点——索引、锁、事务(转)
1. 索引 索引,类似书籍的目录,可以根据目录的某个页码立即找到对应的内容. 索引的优点:1. 天生排序.2. 快速查找.索引的缺点:1. 占用空间.2. 降低更新表的速度. 注意点:小表使用全表扫描 ...
- Docker与虚拟化
核心知识点: 1.虚拟化的定义?虚拟化的核心和目标? 2.虚拟化的分类?Docker属于那种虚拟化? 3.Docker与传统虚拟化的区别?docker是直接在操作系统上实现虚拟化,直接复用本地操作系统 ...
- Database: index
The whole point of having an index is to speed up search queries by essentially cutting down the num ...