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_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)。
推荐阅读
- oracle - 如何通过 Android Studio 4.2.2 创建英文 JavaDocs
- python - python:饼图字体大小
- c# - C# VSTO Office 加载项:“FindRibbons”任务意外失败
- c - 如何在c中的结构中初始化匿名联合
- python - 从 C# 调用带有 out 参数的覆盖方法到 python(使用 pythonnet)
- java - Dagger-Hilt 你忘记应用 Gradle 插件了吗?但我应用了插件
- wso2-am - 引起:java.io.FileNotFoundException: /wso2am-3.2.0/repository\conf\advanced\qpid-config.xml(没有这样的文件或目录)
- gitlab - Gitlab 静态 mkdoc 网站不起作用。可能是什么原因?
- c - 创建一个函数,将每个单词的第一个字母大写并将所有其他字母转换为小写
- python-3.x - 龙卷风招摇授权不起作用