[英]Azure SQL Data Warehouse - Strange DateTime conversion error/ behaviour
I am reading data from data lake (csv) and when running the below query, I am getting a 'Conversion failed when converting date and/or time from character string' error message. 我正在从数据湖(csv)读取数据,并且在运行以下查询时,出现“从字符串转换日期和/或时间时转换失败”错误消息。
select convert(datetime, NullIf(ltrim(rtrim([Date started])), ''), 111)
FROM dl.temp
Looked through the data and checked the source file as well, couldn't spot anything unusual. 浏览数据并检查源文件,找不到任何异常。
As soon as I include the * and change the query to the below everything runs fine and the conversion seem to be doing its job. 当我添加*并将查询更改为以下内容时,一切运行正常,并且转换似乎已完成。
select convert(datetime, NullIf(ltrim(rtrim([Date started])), ''), 111),*
from dl.temp
Out of curiosity also wanted to check the max and minimum date, so running max gives me the following: 出于好奇,我们还想检查最长和最短日期,因此运行max给我以下内容:
However when I search for that particular value like below, I don't get any rows returned. 但是,当我搜索如下所示的特定值时,没有得到任何返回的行。 It seems like it setting it to the column name.
似乎将其设置为列名。 Does anyone know what is going on?
有人知道发生了什么吗?
select *
from dl.temp
where [Date started] = 'Date started'
I am running this against an Azure Data Warehouse. 我正在针对Azure数据仓库运行此程序。
I think you'll find the issue is in your external file format. 我想您会发现问题出在您的外部文件格式中。
In the CREATE EXTERNAL FILE FORMAT you probably need to add FIRST_ROW=2 in your FORMAT OPTIONS. 在CREATE EXTERNAL FILE FORMAT中,您可能需要在FORMAT OPTIONS中添加FIRST_ROW = 2。
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-external-file-format-transact-sql https://docs.microsoft.com/zh-cn/sql/t-sql/statements/create-external-file-format-transact-sql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.