zoukankan      html  css  js  c++  java
  • 组装SQL 临时表 case null

    alter procedure GetTempDataOfCancelProd (@ProdId varchar(500) = null)

    as

    begin

        declare @SqlStr varchar(1000)

       

        set @SqlStr = 'select   a.Prodid as N''ProdId'',

                a.ACT_ProdCancelId as N''CancelID'',

                b.ACT_JobId as N''JobId'',

                c.itemId as N''ItemId'',

                sum(c.ALLOWSCRAPQTY) as N''AllowScrap''

         into #tmpTable

         from prodTable a

             join ACT_JobTable b on a.ProdId = b.ProdId

             join ACT_JobTrans c on b.ACT_JobId = c.ACT_JobId

         where  a.act_prodCancelId = ''cancel''

                and b.ACT_JobRefType = 0

                and c.ALLOWSCRAPQTY >0 ' + case 

                                            when @ProdId is null then ''

                                            else 'and a.ProdId Like ''' + @ProdId + '''' end + '                                            

         group by a.prodId,a.ACT_ProdCancelId,b.act_jobId,c.ItemId

            select * from #tmpTable

        '          

        exec(@SqlStr)

        --print @SqlStr

        --if object_id(tempdb..#tmpTable) is not null

        --begin

        --  drop table #tmpTable

        --end

       

    end

  • 相关阅读:
    面向对象深入:继承01——子类
    面向对象的基础知识——小结
    IP地址配置
    二、RPM包管理-rpm命令管理
    一、软件包管理简介
    关机重启命令
    网络命令
    权限管理命令
    字符截取命令
    shell-正则表达式(二)
  • 原文地址:https://www.cnblogs.com/perock/p/2282018.html
Copyright © 2011-2022 走看看