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. orm总结

    x先谈谈java方面的. mybatis优点是基本啥都有了,sql统一管理,只需接口就可以了,缺点是对于复杂语句的执行还是麻烦,一般还是在程序里解决,自带的动态sql功能较弱不说,重点是调式时还是麻烦 ...

  2. C++实验一

    2-28 #include <iostream> using namespace std; int main() {char x; cout<<"Menu: A(dd ...

  3. django日志,django-crontab,django邮件模块

    django 日志 四大块,格式器,过滤器,处理器,日志管理器 LOGGING = { 'version': 1, 'disable_existing_loggers': True, 'formatt ...

  4. 今天聊一聊Java引用类型的强制类型转换

    实际上基本类型也是存在强制类型转换的,这里简单提一下.概括来讲分为两种: 1.自动类型转换,也叫隐式类型转换,即数据范围小的转换为数据范围大的,此时编译器自动完成类型转换,无需我们写代码 2.强制类型 ...

  5. @Autowired mapper 层次 bean 带红线

    在利用@Autowired 注解创建bean 时候 有时间会带有下滑红色横线 给人一种报错的感觉 下面是去除红线的办法 将颜色红色error 等级降低为黄色warn  即可

  6. 使用virtualenvwrapper模块管理python虚拟环境

    1.pip安装virtualenvwrapper [root@localhost ~]# pip install virtualenvwrapper # 安装virtualenvwrapper [ro ...

  7. 使用Selenium+ChromeDriver登录微博并且获取cookie

    using OpenQA.Selenium;using OpenQA.Selenium.Chrome; public class GetSinaCookie { private static stri ...

  8. Spring Boot+CXF搭建WebService(转)

    概述 最近项目用到在Spring boot下搭建WebService服务,对Java语言下的WebService了解甚少,而今抽个时间查阅资料整理下Spring Boot结合CXF打架WebServi ...

  9. js-事件以及window操作

    属性 当以下情况发生时,出现此事件 onblur 元素失去焦点 onchange 用户改变域的内容 onclick 鼠标点击某个对象 ondblclick 鼠标双击某个对象 onfocus 元素获得焦 ...

  10. bool值的底层应用场景

    这里我们的if 或者while,还有and,or,not 等都是在内部调用一个对象的bool方法,然后返回True或者是False, a = [0, ] # a = [] # print(bool(a ...