zoukankan      html  css  js  c++  java
  • 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 
  • 相关阅读:
    Android 画布绘图
    Android 4.2.2原生Launcher修改使之可以运行过程小结
    canvas的translate、scale、rotate等方法
    WorkSpace介绍
    Libgdx New 3D API 教程之 -- 加载3D场景的背后-第二部分
    Libgdx New 3D API 教程之 -- 使用Libgdx加载模型
    LibGdx----Texture, TextureRegion, SpriteBatch
    libgdx学习之Camera
    Java伪代码
    读大道至简之感
  • 原文地址:https://www.cnblogs.com/Snowfun/p/3158631.html
Copyright © 2011-2022 走看看