Dynamic SQL Store Procedure:
Note:
use variable,you need convert varchar and as a variable,not directly use variable,like this: '+convert(varchar(10),@init_column)+'    '+@the_column_name+'
create procedure sp_getgoodlocationviaplatoon
@the_platoon int
as
begin
declare @the_column_name varchar()
declare @sql varchar()
declare @init_column int
declare @the_column int
begin
select @the_column=max(F_column) from Sys_GoodLocation
select @sql = 'select F_Floor, '
set @init_column=
set @the_column_name=concat('[',@init_column,']') while @init_column<@the_column
begin
set @sql= @sql + 'sum(case F_Column when '+convert(varchar(),@init_column)+' then F_GoodLocationNum else 0 end) as '+@the_column_name+','
--print @sql
set @init_column=@init_column+
set @the_column_name=concat('[',@init_column,']')
end
if @init_column=@the_column
begin
set @sql= @sql + 'sum(case F_Column when '+convert(varchar(),@init_column)+' then F_GoodLocationNum else 0 end) as '+@the_column_name+''
end select @sql= @sql + ' from Sys_GoodLocation where F_Platoon='+convert(varchar(),@the_platoon)+' group by F_Floor order by F_Floor'
exec(@sql)
end
end
go

Call:

exec sp_getgoodlocationviaplatoon
exec sp_getgoodlocationviaplatoon
exec sp_getgoodlocationviaplatoon

Result:

Get WMS Static GoodLocation By Dynamic SQL的更多相关文章

  1. MyBatis(3.2.3) - Dynamic SQL

    Sometimes, static SQL queries may not be sufficient for application requirements. We may have to bui ...

  2. Can I use MyBatis to generate Dynamic SQL without executing it?

    Although MyBatis was designed to execute the query after it builds it, you can make use of it's conf ...

  3. [转]Dynamic SQL & Stored Procedure Usage in T-SQL

    转自:http://www.sqlusa.com/bestpractices/training/scripts/dynamicsql/ Dynamic SQL & Stored Procedu ...

  4. Introduction to Dynamic SQL

    The idea of using dynamic SQL is to execute SQL that will potentially generate and execute another S ...

  5. mybatis Dynamic SQL

    reference: http://www.mybatis.org/mybatis-3/dynamic-sql.html Dynamic SQL One of the most powerful fe ...

  6. mybatis-3 Dynamic SQL

    Dynamic SQL One of the most powerful features of MyBatis has always been its Dynamic SQL capabilitie ...

  7. ABAP动态生成经典应用之Dynamic SQL Excute 程序

    [转自http://blog.csdn.net/mysingle/article/details/678598]开发说明:在SAP的系统维护过程中,有时我们需要修改一些Table中的数据,可是很多Ta ...

  8. myisamchk是用来做什么的?MyISAM Static和MyISAM Dynamic有什么区别?

    myisamchk是用来做什么的? 它用来压缩MyISAM[歌1] 表,这减少了磁盘或内存使用. MyISAM Static和MyISAM Dynamic有什么区别? 在MyISAM Static上的 ...

  9. static lib和dynamic lib

    lib分为 staticlib 和 dynamic lib: 静态lib将导出声明和实现都放在lib中,编译后所有代码都嵌入到宿主程序, 链接器从静态链接库LIB获取所有被引用函数,并将库同代码一起放 ...

随机推荐

  1. C# 微信开发-----微信会员卡(三)激活会员卡

    在会员领取了会员卡之后需要做 一个跳转性激活,模式请看下图: 在创建会员卡的时候需要配置下这个参数的值: memberActivate.aspx页面代码如下: <%@ Page Language ...

  2. pl/sql学习(4): 包package

    本文简单介绍包, 目前来看我用的不多, 除了之前 为了实现 一个procedure 的输出参数是结果集的时候用到过 package. 概念: 包是一组相关过程.函数.变量.常量和游标等PL/SQL程序 ...

  3. burp基本使用

    记录一个burp最基础的小白使用过程: 以firefox为例设置一下代理,代理到127.0.0.1:8090 设置Burp的相关: 1.为Burp添加一个代理ip和端口:如 127.0.0.1:809 ...

  4. Java组合模式

    定义:将对象组合成树形结构以表示  部分--整体的层次结构 组合模式使客户端对单个对象和组合对象保持一致的方式处理 类型:结构型 优点: 1.清楚地定义分层次的复杂对象,表示对象的全部去或部分层次 2 ...

  5. C++中STL常用容器的优点和缺点

    我们常用到的STL容器有vector.list.deque.map.multimap.set和multiset,它们究竟有何区别,各自的优缺点是什么,为了更好的扬长避短,提高程序性能,在使用之前需要我 ...

  6. java代码获取多边形的中心点

    package com.skjd.util; import java.util.ArrayList; import java.util.List; /** * 坐标以及电子围栏相关的工具类 * @au ...

  7. 网络安全第一集之【SQL注入:sqlmap入门】

    1,安装sqlmap和python环境 2,对于环境变量超长问题 3,使用sqlmap: sqlmap.py -u "http://k2.hlxy.net/csdw/news1.asp?dp ...

  8. 一个div实现白眼效果

    巧妙利用border和background-clip   <div class="eye"></div> .eye{ width:150px; height ...

  9. HDU4864:Task(贪心)

    Problem DescriptionToday the company has m tasks to complete. The ith task need xi minutes to comple ...

  10. [CQOI2015]网络吞吐量

    Description: 给你一个图,每个点可以被经过\(a_i\)次,求有多少个人可以走最短路到n点 Hint: \(n \le 500\) Solution: 极其水的一道题,就当做复习最短路板子 ...