执行存储过程总是报 临时表无效
USE [wfp]
GO
/****** Object: StoredProcedure [dbo].[pr_T接口_一代_上下架_网店产品_读取] Script Date: 03/28/2013 19:12:13 ******/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[pr_T接口_一代_上下架_网店产品_读取]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[pr_T接口_一代_上下架_网店产品_读取]
GO
USE [wfp]
GO
/****** Object: StoredProcedure [dbo].[pr_T接口_一代_上下架_网店产品_读取] Script Date: 03/28/2013 19:12:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[pr_T接口_一代_上下架_网店产品_读取]
@dbname varchar(20) --数据库名称
,@wfpuser varchar(100) --操作账号
,@shopid varchar(100) --店铺编号
,@shoptype varchar(100) --店铺类型
as
/*
[调用]
exec wfp..[pr_t接口_一代_上下架_网店产品_读取]
@dbname = N'edb_asqldev.',
@wfpuser = N'edb_b000035',
@shopid = N'7',
@shoptype = N'淘宝'
select * from edb_asqldev..wfpuser_a0305
[功能]:读取网店产品数据,用于执行上下架操作
[输入]:店铺信息,详细请参风参数说明
[输出]:用于执行上下架的数据集
[实现逻辑]
1.判断库存计算方式m..
2.判断是否开启预售
3.计算产品库存
4.网店产品关联库存,并分析执行操作,上架还是下架
5.返回上下架结果集
[作者]:
[版本号]:v1.0
[最后修改时间]:2013-3-14
[历史修改记录]:
-------------------
修改人:朱熹-刘津防
修改原因:为了实现数据同步平台自动上下架
修改内容:1.将启用上下架(备用4)重命名为 是否启用上下架
2.是否更新条形码 默认为False
3.添加自动上下架状态读取 (默认更新,启用更新,不启用更新)
-------------------
*/
exec('if object_id('''+@dbname+'.'+@wfpuser+'wfpuser_a0304autoUpload'') is not null drop table '+@dbname+'.'+@wfpuser+'wfpuser_a0304autoUpload
if object_id('''+@dbname+'.'+@wfpuser+'wfpuser_a0304autoUpload_d'') is not null drop table '+@dbname+'.'+@wfpuser+'wfpuser_a0304autoUpload_d ')
declare @sqltz nvarchar(max)
set @sqltz='
if object_id(''logs..'+@wfpuser+'wfpuser_a0304库存临时表'') is not null drop table logs..'+@wfpuser+'wfpuser_a0304库存临时表
DECLARE @ac0052 nvarchar(500)
SELECT @ac0052=ac0052
FROM '+@dbname+'.wfpcode_ad0527 a
JOIN '+@dbname+'.wfpuser_a0401 b
ON Charindex('',''+Convert(VARCHAR,b.objorder)+'','','',''+Isnull(a.ac0052,'''')+'','')>0
WHERE a.objname='''+@shopid+''' and a.ad0554='''+case when @shoptype ='分销平台' then '淘宝分销' else @shoptype end+'''
AND Isnull(b.ab0007,0)=0
SELECT @ac0052=Isnull(@ac0052,1)
select a.Objid,(case when isnull(sum(b.TN0010),0)>0 then isnull(sum(b.TN0010),0) else 0 end ) tn0010all
,isnull(SUM(case when Charindex('',''+b.ac0016+'','','',''+@ac0052+'','')>0 then b.TN0010 else 0 end),0) tn0010
,isnull(SUM(b.ai0018),0) ai0018all,isnull(SUM(case when Charindex('',''+b.ac0016+'','','',''+@ac0052+'','')>0 then b.ai0018 else 0 end),0) ai0018
,isnull(SUM(b.ti0085),0) ti0085all,isnull(SUM(case when Charindex('',''+b.ac0016+'','','',''+@ac0052+'','')>0 then b.ti0085 else 0&nb