『求助』存储过程错误
CREATE PROCEDURE eip_Report(
@reportowner int, --输入:用户ID
@StartTime datetime, --输入:开始时间
@EndTime datetime --输入:结束时间
)
AS
declare @test as bigint
Begin Tran
BEGIN
Select [reportowner],[StatTime],@test=(sum([MtSucceedNum]) as MtAll),sum([MtErorNum]) AS MtEro,SuM([MoNum]) AS MOALL from eip_ReportNote
where [StatTime] <datediff(hh, '2007-07-01 00:00:00 ',@EndTime) and [StatTime]> DATEDIFF(hh, '2007-07-01 00:00:00 ',@StartTime) and [reportowner]=@reportowner
insert into eip_test(StatTime) values(@test)
END
commit
GO
我想把(sum([MtSucceedNum]) as MtAll)求和这个值付给变量@test
但是出错了如何改正,调试时候提示该处错误
------解决方案--------------------这个肯定不行
你能保证你的查询语句只返回一行吗?
如果返回多行就会有多个sum([MtSucceedNum],你打算把那个值赋给@test呢?
------解决方案--------------------请参考:http://www.xproer.com/bbs/revert.aspx?fid=3&tid=618
------解决方案--------------------Select [reportowner],[StatTime],@test=(sum([MtSucceedNum]) as MtAll),sum([MtErorNum]) AS MtEro,SuM([MoNum]) AS MOALL from
--------------------------
从这条语句来看编译器都不知道你是要赋值还是返回结果集
赋值和返回结果集是不能用同一条实现的
如果你仅仅只是为了给变量赋值你应该这样写
Select @test=(sum([MtSucceedNum]) as MtAll) from 后面是你的条件...