高手进!困惑已久的存储过程建动态临时表问题 String sqlParam = “select accountName,WDName ,'month0_Amount'=(month0_Amount * r.rateNumber)/10000 ,'month1_Amount'=(month1_Amount * r.rateNumber)/10000 ,'month2_Amount'=(month2_Amount * r.rateNumber)/10000 ,'month3_Amount'=(month3_Amount * r.rateNumber)/10000 ,'month4_Amount'=(month4_Amount * r.rateNumber)/10000 ,'month5_Amount'=(month5_Amount * r.rateNumber)/10000 ,'month6_Amount'=(month6_Amount * r.rateNumber)/10000 ,'20090706'=(select (weeklyAmount * r.rateNumber)/10000 from accountWeekly aw where weeklyDate = '20090706' and aw.accountId = v.accountId ) ,'20090713'=(select (weeklyAmount * r.rateNumber)/10000 from accountWeekly aw where weeklyDate = '20090713' and aw.accountId = v.accountId ) into #t from viewDisplayInfo v,rate r where bibie = r.rateId and inout = 1 and ZHID = 1 order by WDName desc” //sqlParam这个语句是自动生成的,要传到存储过程中 cmd1 = con.prepareCall("{call execSql_proc(?)}"); cmd1.setString(1, sqlParam); cmd1.execute();
报错如下:java.sql.SQLException: 对象名 '#t' 无效。 java.lang.NumberFormatException: For input string: "null"
SQL code
--存储过程是个判断执行那条语句
create proc execSql_proc
@sql varchar(5000)
as
begin
IF EXISTS (SELECT * FROM tempdb.#t )
begin
drop table tempdb.#t
exec @sql
end
else
exec @sql
end
直接在sql里面执行 exec execSql_proc 'select select accountName,WDName into #t from viewDisplayInfo v,rate r where bibie = r.rateId and inout = 1 and ZHID = 1'会报错:对象名 '#t' 无效
create proc execSql_proc
@sql varchar(5000)
as
begin
IF EXISTS (SELECT * FROM tempdb.#t )
drop table tempdb.#t
go
exec @sql
end
------解决方案-------------------- 你把整个过程代码贴一下
------解决方案--------------------
------解决方案--------------------
SQL code
create proc execSql_proc
@sql varchar(500)
as
begin
IF EXISTS (SELECT * FROM #t)
drop table #t
go
create table #t(accountName varchar(100),WDName varchar(100))
insert into #t
exec @sql
end
exec execSql_proc 'select accountName,WDName from viewDisplayInfo v,rate r bibie = r.rateId and inout = 1 and ZHID = 1'
------解决方案--------------------
SQL code
create proc execSql_proc
@sql varchar(500)
as
begin
IF object_id('#t') is not null
drop table #t
go
create table #t(accountName varchar(100),WDName varchar(100))
go
insert into #t
exec @sql
end
exec execSql_proc 'select accountName,WDName from viewDisplayInfo v,rate r bibie = r.rateId and inout = 1 and ZHID = 1'
------解决方案--------------------