- 论坛徽章:
- 0
|
写了一个存储过程, 就是通过输入日期, 形成表名, 然后根据查询条件算出某一字段的总和, 但是总报语法错误, 代码如下
create procedure proc_billAgent (@StartDay char(20),
@EndDay char(20),
@StartTime char(20),
@EndTime char(20),
@InfoCode char(4))
as
declare @Sql char(100)
declare @Table1 char(50)
declare @Table2 char(50)
declare @Access1 decimal(4, 0)
declare @Access2 decimal(4, 0)
declare @Access decimal(5, 0)
declare @Fee1 decimal(6,2)
declare @Fee2 decimal(6,2)
declare @Fee decimal(7,2)
begin
/*----------获取两个数据表的名称----------*/
select @Table1 = "sjc_TJAgentWorkSum_" + @StartDay
select @Table2 = "sjc_TJAgentWorkSum_" + @EndDay
/*----------获取第一个表的相关类别的访问次数, 费用总和----------*/
select @Access1 = sum(ceiling(TimeSpan/60)), @Fee1 = sum(Fee)
from @Table1 (此处报错)
where AccessTime >= @StartTime and InfoCode = @InfoCode
/*----------获取第二个表的相关类别的访问次数, 费用总和----------*/
select @Access2 = sum(ceiling(TimeSpan/60)), @Fee2 = sum(Fee)
from @Table2
where AccessTime <= @EndTime and InfoCode = @InfoCode
select @Access = @Access1 + @Access2 as "Time Length"
select @Fee = @Fee1 + @Fee2 as "Total Fee"
end |
|