1. create PROCEDURE USP_GetDetail(@ObjectName nvarchar(50))
  2. as 
  3. Begin 
  4.     declare @type varchar(10)
  5.     select @type=[type] from sys.objects with(nolock) where name=@ObjectName
  6.     
  7.     case @type
  8.     WHEN 'U' THEN
  9.         exec('select count(1) as 总行数 from ' + @ObjectName + ' with(nolock)') 
  10.         exec('select top 100 * from ' + @ObjectName + ' with(nolock)') 
  11.     WHEN 'P' THEN
  12.         exec('sp_helptext '+ @ObjectName)
  13.     WHEN 'FN' THEN
  14.         exec('sp_helptext '+ @ObjectName)
  15.     else
  16.         select '不明对象,不能取出对应信息.' as ErrorMessage
  17.     End    
  18. End 

提示错误如下:

正确写法如下:

看看你知道问题错在哪里没有

  1. create PROCEDURE USP_GetDetail(@ObjectName nvarchar(50))
  2. as 
  3. Begin 
  4.     declare @type varchar(10)
  5.     select @type=[type] from sys.objects with(nolock) where name=@ObjectName
  6.     declare @str nvarchar(100)
  7.     
  8.     select @str = case @type
  9.     WHEN 'U' THEN 
  10.         'select count(1) as 总行数 from ' + @ObjectName + ' with(nolock)' + ' ' 
  11.                         + 'select top 100 * from ' + @ObjectName + ' with(nolock)'
  12.     WHEN 'P' THEN
  13.         'sp_helptext '+ @ObjectName
  14.     WHEN 'FN' THEN
  15.         'sp_helptext '+ @ObjectName
  16.     else
  17.         'select '+ '''不明对象,不能取出对应信息.''' + ' as ErrorMessage'
  18.     End    
  19.  
  20.     exec(@str)
  21. End 

Stored Procedures CASE 用法错误的更多相关文章

  1. 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 ...

  2. sql case 用法总结

    快下班了,抽点时间总结一下sql 的 case 用法. sql 里的case的作用: 用于计算条件列表的表达式,并返回可能的结果之一.sql 的case 类型于编程语言里的 if-esle if-el ...

  3. [MySQL] Stored Procedures 【转载】

    Stored routines (procedures and functions) can be particularly useful in certain situations: When mu ...

  4. 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 ...

  5. An Introduction to Stored Procedures in MySQL 5

    https://code.tutsplus.com/articles/an-introduction-to-stored-procedures-in-mysql-5--net-17843 MySQL ...

  6. Cursors in MySQL Stored Procedures

    https://www.sitepoint.com/cursors-mysql-stored-procedures/ After my previous article on Stored Proce ...

  7. MySQL Error Handling in Stored Procedures 2

    Summary: this tutorial shows you how to use MySQL handler to handle exceptions or errors encountered ...

  8. [转]How to: Execute Oracle Stored Procedures Returning RefCursors

    本文转自:http://www.telerik.com/help/openaccess-orm/openaccess-tasks-oracle-execute-sp-result-set.html I ...

  9. SQL进阶随笔--case用法(一)

    SQL进阶一整个是根据我看了pdf版本的整理以及自己的见解整理.后期也方便我自己查看和复习. CASE 表达式 CASE 表达式是从 SQL-92 标准开始被引入的.可能因为它是相对较新的技术,所以尽 ...

随机推荐

  1. H2 database 操作操作内存表

    本例开发工具为 NetBeans,使用b2前提安装jdk. 第一步:在官网下载驱动包 :http://www.h2database.com ,本例版本为: h2-1.4.192.jar 第二步:安装开 ...

  2. 公网yum 源地址

    1. centos5.*  公网yum 源地址 [root@web ~]# cd /etc/yum.repos.d/[root@web yum.repos.d]# wget -O /etc/yum.r ...

  3. 【BZOJ4012】[HNOI2015]开店 动态树分治+二分

    [BZOJ4012][HNOI2015]开店 Description 风见幽香有一个好朋友叫八云紫,她们经常一起看星星看月亮从诗词歌赋谈到人生哲学.最近她们灵机一动,打算在幻想乡开一家小店来做生意赚点 ...

  4. 【BZOJ4264】小C找朋友 随机化

    [BZOJ4264]小C找朋友 Description 幼儿园里有N个小C,两个小C之间可能是朋友也可能不是.所有小C之间的朋友关系构成了一个无向图,这个无向图中有M条边. 园长ATM发现对于两个(不 ...

  5. (转)ConcurrentModificationException异常原因和解决方法

    原文地址: http://www.cnblogs.com/dolphin0520/p/3933551.html 一.ConcurrentModificationException异常出现的原因 先看下 ...

  6. HTML 学习笔记 JQuery(盒子操作)

    这边博客详细的讲述一下JQuery中关于盒子模型的一些方法 offset([coordinates])方法 获取匹配元素在当前适口的相对偏移 返回的对象包含两个模型属性:top和left 以像素计.此 ...

  7. Grunt学习笔记【6】---- grunt-contrib-requirejs插件详解

    本文主要讲如何使用Grunt实现RequireJS文件压缩. 一 说明 ES6出来前,RequireJS是JavaScript模块化最常用的方式之一.对于使用RequireJS构建的项目,要实现打包压 ...

  8. python数据分析之:数据清理,转换,合并,重塑(二)

    一:移除重复数据 DataFrame经常出现重复行,就像下面的这样 In [7]: data=DataFrame({'k1':['one']*3+['two']*4,'k2':[1,1,2,3,3,4 ...

  9. SAP RFC 的介绍

    第一部分 RFC技术 什么是RFC? RFC是SAP系统和其他(SAP或非SAP)系统间的一个重要而常用的双向接口技术,也被视为SAP与外部通信的基本协议.简单地说,RFC过程就是系统调用当前系统外的 ...

  10. python mmap使用记录

    1.写文件 with open('??', 'r+b') as f: with contextlib.closing(mmap.mmap(f.fileno(), size, flags=mmap.MA ...