• Get WMS Static GoodLocation By Dynamic SQL


    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(
    32) declare @sql varchar(8000) 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=1 set @the_column_name=concat('[',@init_column,']') while @init_column<@the_column begin set @sql= @sql + 'sum(case F_Column when '+convert(varchar(10),@init_column)+' then F_GoodLocationNum else 0 end) as '+@the_column_name+',' --print @sql set @init_column=@init_column+1 set @the_column_name=concat('[',@init_column,']') end if @init_column=@the_column begin set @sql= @sql + 'sum(case F_Column when '+convert(varchar(10),@init_column)+' then F_GoodLocationNum else 0 end) as '+@the_column_name+'' end select @sql= @sql + ' from Sys_GoodLocation where F_Platoon='+convert(varchar(10),@the_platoon)+' group by F_Floor order by F_Floor' exec(@sql) end end
    go

    Call:

    exec sp_getgoodlocationviaplatoon 1
    exec sp_getgoodlocationviaplatoon 2
    exec sp_getgoodlocationviaplatoon 3

    Result:

  • 相关阅读:
    spring mvc 参数校验
    spring-boot 配置jsp
    java 多线程之取消与关闭
    spring transaction 初识
    java 读取环境变量和系统变量的方法
    每天一命令 git checkout
    每天一命令 git stash
    每天一命令 git reset
    log4j2配置详解
    专业名词及解释记录
  • 原文地址:https://www.cnblogs.com/AriLee/p/10752542.html
Copyright © 2020-2023  润新知