81,091
社区成员
发帖
与我相关
我的任务
分享
--悲哀:用Java调用SQL Server 2005的存储过程报错--
错误代码:该语句没有返回结果集。com.microsoft.sqlserver.jdbc.SQLServerException......
---我的存储过程若用临时表就报错,若不用临时表就运行OK!
---是怎么回事啊?
--存储过程代码如下:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[mobile_status_sum_date] @fromDate varchar(19), @toDate varchar(19)
/*
exec mobile_status_sum_date '2009-01-01','2009-11-29'
*/
as
begin
/*
if(ISNULL(@fromDate,'')='')
set @fromDate=convert(varchar(8),getdate()-1,121)+'01'
if(ISNULL(@toDate,'')='')
set @toDate=convert(varchar(10),getdate()-1,121)
*/
---明细表
create table #Temp_db1(
province_name nvarchar(20),
mobileNo varchar(50),
userState int,
cDate datetime,
uDate datetime );
--汇总表
create table #Temp_db2(
id int identity(1,1),
province_name nvarchar(20),
sum_active int, --激活用户
sum_unactive int, --未激活用户
sum_activing int --活跃用户
);
insert into #Temp_db1(province_name, mobileNo, userState, cDate, uDate)
select ph.province_name,
un.mobileNo, un.userState, un.cDate, un.uDate
from (
select mobile as mobileNo, 1 as userState, cdate, udate
from IMSI2MOBILE im
where (uDate>=@fromDate or ISNULL(@fromDate,'')='')
and (uDate<=@toDate or ISNULL(@toDate,'')='')
union all
select mobileNO, userState, cdate, udate
from unActiveUser un where userState=0
and (uDate>=@fromDate or ISNULL(@fromDate,'')='')
and (uDate<=@toDate or ISNULL(@toDate,'')='')
) un
left join PhoneAreaMap ph on substring(un.mobileNO,1,7)=ph.prefix;
insert into #Temp_db2(province_name, sum_active, sum_unactive, sum_activing)
select province_name,
sum(case when userState=1 then 1 else 0 end) as sum_active,
sum(case when userState=0 then 1 else 0 end) as sum_unactive,
sum(case when userState=1 and datediff(day,uDate,convert(datetime,@todate,120))<=3 then 1 else 0 end) as sum_activing
from #Temp_db1
where province_name is not null
group by province_name
order by sum_active desc, sum_unactive desc, sum_activing;
insert into #Temp_db2(province_name, sum_active, sum_unactive, sum_activing)
select '合计',
sum(sum_active) as sum_active,
sum(sum_unactive) as sum_unactive,
sum(sum_activing) as sum_activing
from #Temp_db2;
select province_name, sum_active, sum_unactive, sum_activing from #Temp_db2;
drop table #Temp_db1, #Temp_db2;
end
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO