如题,执行存储语句后,显示完成命令,但是临时表CBHTxlfx并未创建,里面的SQL插入 语句单独执行是没问题的 我把创建表格及插入单独拿出来执行也是没问题的 但直接运行存储去无法创建临时表,检查好久不知道问题在哪? 查询临时表无记录:对象名 'CBHTxlfx' 无效 ---以下为存储语句: CREATE PROC CBHTProc @bgdate date, @eddate date, @wftypename varchar(max), @wfname varchar(max), @area varchar(max) AS BEGIN IF NOT EXISTS (SELECT * FROM sysobjects WHERE name LIKE 'CBHTxlfx' AND type ='U') CREATE TABLE [dbo].[CBHTxlfx] ( [A] [varchar](1000) NULL, [B] [varchar](1000) NULL, [C] [varchar](1000) NULL, [D] [varchar](1000) NULL, [E] [varchar](1000) NULL, [F] [varchar](1000) NULL, [G] [float] NULL ) ON [PRIMARY] ELSE DELETE FROM CBHTxlfx; INSERT INTO CBHTxlfx SELECT A,B,C,D,E,F,G FROM ( SELECT A,B,C,D,E,F,G FROM TABLE1 UNION ALL SELECT A,B,C,D,E,F,G FROM TABLE2 )AA WHERE 1=1 AND A IN (select col from SplitIn(@area,',')) AND B BETWEEN @bgdate AND @eddate AND C IN (select col from SplitIn(@wftypename,',')) AND D IN (select col from SplitIn(@wfname,',')) ORDER BY A,B,C,D DESC; declare @ck varchar(8000) declare @sql varchar(8000) select @ck=isnull(@ck+',','')+'['+ F + ']' from CBHTxlfx group by F order by F set @sql='select * from CBHTxlfx pivot(avg(G) for F in ('+@ck+')) dd' exec(@sql) END |
最佳回答 |
||||
0
|
|