当前位置: 代码迷 >> Sql Server >> SQL动态话语不能执行,求高手!
  详细解决方案

SQL动态话语不能执行,求高手!

热度:44   发布时间:2016-04-24 18:30:02.0
SQL动态语句不能执行,求高手!!
Create Procedure [dbo].[P_transfer_photo_test]
(
@Month_id Varchar(6)
)
As
Begin

Declare @Sql Varchar(4000)
    
Create Table #Fact_Temp_POP_User_Raw_Data(
                                Raw_id int identity(1, 1),
                                Data_id int NULL,
Submit_Date varchar(50) NULL,
                                User_id int NULL,
                                POPDB_id int NULL,
Chain_Group_id int NULL,
Chain_id int NULL,
Channel_id int NULL,
Client_POP_id varchar(50) NULL,
POP_Name varchar(500) NULL,
POP_Address varchar(1000) NULL,
Source_Type varchar(50) NULL,
Task_Group varchar(1000) NULL,
Category_id int NULL,
Subcategory_id int NULL,
SKU_Cluster_id int NULL,
Brand_id int NULL,
                                SKU varchar(500) NULL,
                                Quest_Task varchar(500) NULL,
                                Data_SubTask varchar(500) NULL,
                                Subtask_Value varchar(1000) NULL,
                                Subtask_Type varchar(1000) NULL,
                                City_id int NULL,
                                District_Value varchar(50) NULL,
                                Region_Value varchar(50) NULL,
                                Area_Value varchar(50) NULL
)

    -- Load photo data into temporary table
    Set @Sql = 'Insert Into #Fact_Temp_POP_User_Raw_Data 
  (Data_id, Submit_Date, User_id, POPDB_id, Chain_Group_id, Chain_id, Channel_id, Client_POP_id, POP_Name, 
   POP_Address, Source_Type, Task_Group, Category_id, Subcategory_id, SKU_Cluster_id, Brand_id, SKU, Quest_Task, 
   Data_SubTask, Subtask_Value, Subtask_Type, City_id, District_Value, Region_Value, Area_Value)
                Select Data_id, Submit_Date, User_id, POPDB_id, Chain_Group_id, Chain_id, Channel_id, Client_POP_id, POP_Name, 
                       POP_Address, Source_Type, Task_Group, Category_id, Subcategory_id, SKU_Cluster_id, Brand_id, SKU, Quest_Task, 
                       Data_SubTask, Subtask_Value, Subtask_Type, City_id, District_Value, Region_Value, Area_Value
                From MonitorNestleHK_ICE.dbo.Fact_' + @Month_id + 'M_POP_User_Raw_Data Where Subtask_Type = ''拍照''' 

    Exec @Sql

End




-- 执行
exec [dbo].[P_transfer_photo_test] '201401'


-- 报错
消息 203,级别 16,状态 2,过程 P_transfer_photo_test,第 49 行
The name 'Insert Into #Fact_Temp_POP_User_Raw_Data 
  相关解决方案