我正在尝试将数据从加载的CSV文件转换为Azure表,但是我遇到了其中一个值加载到字符串中并且表中的等效值为十进制的问题。 / p>
@ProdOutput =
EXTRACT
[p_description] string,
[p_code] string,
[p_price] string,
[p_colour] string
FROM "testing/martin/items.csv"
USING Extractors.Csv(skipFirstNRows:1);
// @items has been brought in from a table in Data Lake Analytics
@holdings_query =
SELECT ROW_NUMBER() OVER (ORDER BY h.code) AS rn,
h.description AS Description,
h.cd AS Code,
h.priceGBP AS Price,
h.col AS Colour
FROM @items AS h;
@result =
SELECT
p_description == Description ? p_description : String.Concat("Mismatch", p_description, " !! ", Description) AS [Desc],
p_code == Code ? p_description : String.Concat("Mismatch", p_code, " !! ", Code) AS [Code],
p_price == Price ? p_price: String.Concat("Mismatch", p_price, " !! ", Price) AS [Price]
FROM @holdings_query AS h
LEFT OUTER JOIN @prod_data AS p ON h.Code == p.p_code;
问题是我希望EXTRACT语句通常将所有内容都作为字符串引入,因为我并不总是知道每个列的类型。因此,当我在最终声明中进行比较时,我想将价格从十进制(如表中所示)转换为字符串,以便与CSV中的内容进行比较。
我尝试过ToString(),ToString(" G"),(字符串?),但它们都会抛出错误。我做错了什么?
TIA 马丁
示例数据:
Items.csv:
"项目1"" IT1"" 3.65"
"项目2"" IT2"" 4.00"
"项目3"" IT3"" 524.2123"
@items表:
" Item1"," IT1",3.65
" Item2"," IT2",4.00
" Item3"," IT3",524.2123
答案 0 :(得分:1)
在Decimal.Parse
类型上尝试string
。此方法" ...将数字的字符串表示形式转换为其十进制等效数"。我得到以下语句,其中p_price
是字符串值:
@result =
SELECT
Decimal.Parse(p.p_price) == h.Price ? 1 : 0 AS isEqual
...