存储过程的表名是不确定的,能不能用字符串拼接啊
create proc P_CRE_TMP
@startDate date, @endDate date
as
begin
declare @date date, @mess varchar(50)
select @date =@startDate
while @date<=@endDate
begin
insert into TJ_PB_ARRIVE_PJ_TAB
select Fld_Print_Date,
S.Fld_Station_Code,
count(*) 批,
sum(Fld_Num) 件
from IQ_BAG_INDEX_TAB_2011 I
join V_STATION_ALL_TAB S on S.Fld_Station_Code = I.Fld_Arrive_Station_Code and S.Fld_Filiale_Code in (select Fld_Filiale_Code from FILIALE_TAB where Fld_Flag<>'9')
where Fld_Print_Date = convert(char(8),@date,112)
and Fld_Waste_Code = '0'
and Fld_Ticket_Type in ('0','1')
group by Fld_Print_Date,S.Fld_Station_Code
select @mess = convert(char(8),@date,112)
print @mess
select @date = dateadd(dd,1,@date)
commit
end
end;
上面的那个IQ_BAG_INDEX_TAB_2011表我想报年份改成我输入的参数。怎么改啊。。。
@startDate date, @endDate date
as
begin
declare @date date, @mess varchar(50)
select @date =@startDate
while @date<=@endDate
begin
insert into TJ_PB_ARRIVE_PJ_TAB
select Fld_Print_Date,
S.Fld_Station_Code,
count(*) 批,
sum(Fld_Num) 件
from IQ_BAG_INDEX_TAB_2011 I
join V_STATION_ALL_TAB S on S.Fld_Station_Code = I.Fld_Arrive_Station_Code and S.Fld_Filiale_Code in (select Fld_Filiale_Code from FILIALE_TAB where Fld_Flag<>'9')
where Fld_Print_Date = convert(char(8),@date,112)
and Fld_Waste_Code = '0'
and Fld_Ticket_Type in ('0','1')
group by Fld_Print_Date,S.Fld_Station_Code
select @mess = convert(char(8),@date,112)
print @mess
select @date = dateadd(dd,1,@date)
commit
end
end;
上面的那个IQ_BAG_INDEX_TAB_2011表我想报年份改成我输入的参数。怎么改啊。。。
...全文
相关推荐
在Sql Server查询语句中能不能用变量表示表名
这通常涉及将字符串拼接成完整的SQL命令,然后使用`EXEC`或`sp_executesql`存储过程来执行这个命令。
存储过程拼接字符串
在SQL语言中,存储过程是一种预编译的SQL语句集合,它可以包含复杂的逻辑和控制流,用于执行数据库中的重复性任务。当我们需要在存储过程中拼接字符串时,通常是为了解决动态SQL构造或者生成报告等需求。
SqlServer存储过程实现及拼接sql的注意点
在本文中,我们将深入探讨如何在SQL Server中创建存储过程以及在拼接SQL语句时需要注意的关键点。
mssql存储过程表名和字段名为变量的实现方法
通过构建字符串并使用`sp_executesql`执行,我们可以灵活地处理不确定的表和字段。然而,使用动态SQL时应谨慎,因为它可能导致性能下降并且可能引入安全风险。
深入mysql存储过程中表名使用参数传入的详解
`date_str` 用于存储当前日期的格式化字符串,而 `table_prefix` 是用来构建表名的基础部分。


