首页 > 解决方案 > 使用过程将数据从外部表移动到主表

问题描述

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

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 行

标签: sql-server

解决方案


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


推荐阅读