Sql server 使用以下步骤将数据从外部表移动到主表

Sql server 使用以下步骤将数据从外部表移动到主表,sql-server,Sql Server,如果我手动传递值而不是使用变量,代码就会工作。但是,当我向过程传递参数时,相同的代码不起作用 ALTER PROC [OPTI].[Refreshfinal_GetAllActions] @RunDate [Varchar],@CN [Varchar] AS begin begin tran print 'deleteing records from Stage_GetAllActions' delete from Opti.[Stage_GetAllActions] where Input_

如果我手动传递值而不是使用变量,代码就会工作。但是,当我向过程传递参数时,相同的代码不起作用

ALTER PROC [OPTI].[Refreshfinal_GetAllActions] @RunDate [Varchar],@CN [Varchar] AS 
begin
begin tran
print 'deleteing records from Stage_GetAllActions'
delete from Opti.[Stage_GetAllActions] where Input_Date = @RunDate AND Country = @CN
print 'inserting records into Stage_GetAllActions'
insert into Opti.[Stage_GetAllActions]
select distinct
case when ltrim(rtrim(Country)) ='' then null else Country end,
case when ltrim(rtrim(Etl_Batch)) ='' then null else Etl_Batch end,
case when ltrim(rtrim(Input_Date)) ='' then null else Input_Date end,
case when ltrim(rtrim(ActionID)) ='' then null else ActionID end,
case when ltrim(rtrim(ActionName)) ='' then null else ActionName end,
case when ltrim(rtrim(Api_Executed_Datetime)) ='' then null else Api_Executed_Datetime end
from [Opti].[Ext_Stage_GetAllActions]
where Input_Date = @RunDate AND Country = @CN;
commit tran
end 
该代码将数据从外部表传输到数据库表


但是它给出了受影响的0行,即使外部表中有数据

可能会发生一些隐式截断,请尝试显式定义varchar参数大小,例如@RunDate[varchar](30)、@CN[varchar](100)。

不是“可能有一些隐式截断”;绝对做隐式截断。好电话+1.