具有 Visual Studio 个派生列的 SSIS

SSIS with Visual Studio Derived Column

我正在尝试从文本文件中获取列表并将其导出到 excel。

Rank,Millions,Name,Country,Source of wealth
1,12700,Lakshmi Mittal and family, India,Steel
2,12315,Alisher Usmanov, Russia,Mining and Investment
3,9500,Roman Abramovich, Russia,Oil and industry
4,8600,Sri and Gopi Hinduja, India,Industry and Finance
5,7580,Leonard Blavatnik, Russia,Industry
6,7400,Ernesto and Kirsty Bertarelli, Switzerland &  United  Kingdom,Pharmaceuticals
7,7350,Gerald Grosvenor, 6th Duke of Westminster, United Kingdom,Property
8,7083,David and Simon Reuben, United Kingdom,Property and Internet
9,6600,John Fredriksen and family, Norway,Shipping and oil services
10,5900,Galen Weston, George Weston and family, Canada,Retailing
11,5490,Charlene de Carvalho-Heineken and Michel Carvalho, Netherlands,Inheritance, banking, brewing (Heineken)
12,4300,Hans Rausing and family, Sweden,Packaging
13,4100,Joseph Lau, China,Property
14,,Paul Chuckle, UK, IT Training
15,4300,Nicky Oppenheimer, South Africa,Mining, Diamonds
16,3900,Kirsten & Jorn Rausing, Sweden,Inheritance, Investment
17,3400,Sir Richard Branson, United Kingdom,Internet, Transport, Finance
18,3300,Sir Philip and Lady Green, United Kingdom,Retailing
19,,Barry Chuckle, UK, Comedy
20,,Roger Chuckle,UK,SSIS consultancy

对于排名 14、19 和 20,“百万”列为空字符串。我已经通过使用条件拆分将数据与指定了百万的行和未指定百万的行分开。我现在要做的是获取未指定的 3 行,并使用派生列转换写入 "Not Specified"。我想我可以做类似的事情(在表达式选项卡中):

Millions=="Not Specified"

然而,当我在输出上 运行 一个数据查看器时,三列在百万列中显示 "False"。

我做了一个奇怪的解决方法,但我确信有更好的方法:

Millions == "" || Millions != "" ? "Not Specified" : "Not Specified"

有人能告诉我为什么我不能使用我的第一个解决方案吗?我假设它与布尔值有关,但数据类型是字符串。

首先,您是否有特殊原因为什么要使用条件拆分将 "Millions" 字段的空值记录分开?您可以只使用派生列转换并在派生列选项卡下 select:替换 'Millions'。在表情栏可以输入:

`Millions=="" ? "Not specified" : Millions`

这意味着如果 Millions 字段有空值,将其替换为 "Not specified"(真条件),或者相反,只插入现有值(假条件)。你是对的,数据类型是字符串,但表达式求值总是指向布尔值。让我简单解释一下为什么你不能只使用 Millions=="Not specified"。 Expression 需要一些参数来评估,因此您必须指定如果表达式评估为 true 或 false 会发生什么。您可以将此运算符视为 if/else 语句的简化版本。所以,你的第一个解决方案的问题是你没有指定如果 Millions=="" 会发生什么。希望这对您有所帮助。