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. mysql的表映射

    参考博客:https://blog.csdn.net/shushugood/article/details/79925150 1.服务器上的操作 在服务器上mysql创建一个实例,名为test_db, ...

  2. C#常用的单元测试框架

    C#常用的单元测试框架有XUnit .NUnit .MSTest 做过单元测试的同学大概都知道以上几种测试框架,这几种框架除了标注测试类和方法的特性用的不一样之外,XUnit 和 NUnit 是非常相 ...

  3. 解决Eclipse启动时报Initializing Java Tooling异常信息

    1.启动Eclipse报错:An internal error occurred during: "Initializing Java Tooling".java.lang.Nul ...

  4. Python中的 @staticmethod@classmethod方法

    python类中有三种方法,常见的是实例方法,另外两种是staticmethod装饰的静态方法,和classmethod装饰的类方法. 1.对比 流畅的python里,用一个例子进行了对比: (1)两 ...

  5. 七天开发进度(七)(微信小程序版(二)记账本)

    终于把小程序版弄完了,不过这并不能称之为是我的作品,因为我还没有彻底学会小程序,对JavaScript语言还有很多不会的地方,没有掌握, 这次的程序是通过学习网上的多个教程,多个案例结合拼凑模仿者人家 ...

  6. PHP var_dump()函数输出不完整,有省略号?解决办法

    xdebug.var_display_max_children=10240xdebug.var_display_max_data=10240xdebug.var_display_max_depth=1 ...

  7. mysql 使用教程 入门

    转载 http://www.cnblogs.com/mr-wid/archive/2013/05/09/3068229.html MySQL有三大类数据类型, 分别为数字.日期\时间.字符串, 这三大 ...

  8. es6学习笔记-Symbol

    概述 ES5 的对象属性名都是字符串,这容易造成属性名的冲突.比如,你使用了一个他人提供的对象,但又想为这个对象添加新的方法(mixin 模式),新方法的名字就有可能与现有方法产生冲突.如果有一种机制 ...

  9. 【自动化测试】使用Java+selenium填写验证码成功登录

    这是我第一次发博客,若有问题,请多多指教! 本次是为了帮忙解决,如果在平时自动化遇到有验证码填写的情况,我们如何成功登录情况. 思路: 首先我们先将验证码复制并保存成一个图片,然后使用tesserac ...

  10. 版本管理_git

    git 世界上最好的版本管理工具,分布式版本控制系统. 林纳斯-托瓦斯,自由主义教皇(git.linux) git 不管理空文件夹 对比于 SVN mkdir XX        创建一个空目录 XX ...