how do I convert date format using bteq script? - database

I'm loading data from a flat file which the date data are in 20150605 format....However, I need to convert it into yyy-mm-dd before loading it into Teradata. I tried the following, but it unfortunately failed.
Values
( Format(:a, 'YYYY-MM-DD')
);
How do I convert this type of data conversion. For others, it would be
(:a (integer))
if I've not mistaken...

The FORMAT clause describes the external data. Using this Teradata-specific cast syntax:
(:a (DATE, FORMAT 'yyyymmdd'))
For something other than FastLoad / TPT LOAD, you could also use
CAST(:a AS DATE FORMAT'yyyymmdd')

Related

Azure Data Factory copy activity failed with Exception ERROR [22007] Timestamp is not recognized?

I am using Azure Data Factory to copy data from CSV to Snowflake, the copy executes fine but it has an error when it comes to copy Date from the CSV which has this value (14/01/2000), if the Date is (12/10/2000) or less, it works very well.
Here is the error message:
ErrorCode=UserErrorOdbcOperationFailed,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=ERROR [22007] Timestamp ‘14/01/2000’ is not recognized
I tried to adjust the format of the date in the copy activity to be dd/MM/yyyy or change the Culture to en-UK as the below image but it has the same issue.
I tried to use all the possible types of date in Snowflake as below but I still have the same issue:
DATE
DATETIME
TIMESTAMP
TIMESTAMP_LTZ
Snowflake doesn't supports format as DD/MM/YYYY and even it supports MM/DD/YYYY it can lead to incorrect dates (05/02/2013 could be interpreted as May 2, 2013 instead of February 5, 2013).
So this:
select '14/01/2000'::timestamp;
produces:
Timestamp '14/01/2000' is not recognized
while this:
select '01/14/2000'::timestamp;
produces:
2000-01-14 00:00:00.000
Same for:
select '14/01/2000'::date;
select '01/14/2000'::date;
The guidelines for how to use date/timestamp formats are described here.
In your case one way to get that value as a date is to use the to_date function, like this:
select to_date('14/01/2000', 'DD/MM/YYYY');
gives me:
2000-01-14

String Date Format Issue in SQL Server

In SQL Server, I have imported a csv using Imprt Flat file option. The file contains string columns which got converted into nvarchar(50) datatype.
The csv contains date values.
I need to load this data containing the date columns (in format 12/16/2020 19:09:58) to 2020-12-16 19:09:58.000 .
I tried using the below way using convert.
select convert(datetime, delta_val, 101) from dbo.my_table;
But getting the below error
Conversion failed when converting date and/or time from character string.
Is there any way to resolve this issue? have tried using cast and format methods as well. Same issue persists.
As suggested by HoneyBadger, used try_convert. Working now.
select try_convert(datetime, delta_val) from dbo.my_table;

Convert from 'YYYYMMDD' format to to SQL Datetime2

I have an issue concerning conversion in SSIS.
I'm trying to convert StartDATE from DT_WSTR to Datetime2 (for SQL Server)
My date originaly looks like this 20140804 but I need to convert it to Datetime2 in such format 2014-08-04 00:00:00.0000000.
What I've done earlier with the StartDATE Column is:
RTRIM(DATSTHYRA)
Since I need to remove blank spaces...
I figured I can use the already Derived Column and add a new expression to convert it to Datetime2 but I'm running into issues and can't really find a topic online that covers my issue.
You can do it in a single step.
Add Derived Column transformation - transform your YYYYMMDD string to YYYY-MM-DD with SUBSTRING functions and then - cast to DT_DBTIMESTAMP2 with scale needed. This would yield an expression like
(DT_DBTIMESTAMP2, 7)(SUBSTRING([StartDATE],1,4) + "-" + SUBSTRING([StartDATE],5,2)
+ "-" + SUBSTRING([StartDATE],7,2))
Then configure Error Output on this Derived Column transformation to capture and handle conversion errors.
In SSIS, you can use data conversion transformation, the data type mapping is database timestamp with precisionin SSIS is for datetime2 in SQL Server.

Unable to retrieve date columns in hive

I am finding difficulty when it comes to retrieving date values in hive. My query is
create external table test1(DISPLAYSCALE int, CREATED_DATE date, LAST_EDITED_DATE date)
ROW FORMAT SERDE 'com.esri.hadoop.hive.serde.JsonSerde' STORED AS INPUTFORMAT 'com.esri.json.hadoop.UnenclosedJsonInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat';
When I try to use the select * from test1 limit5 I get this error;
Failed with exception
java.io.IOException:java.lang.ClassCastException:
org.apache.hadoop.hive.serde2.io.DateWritable cannot be cast to
org.apache.hadoop.io.Text
As per the json the datatype for CREATED_DATE and CREATED_DATE are esriFieldTypeDate and the values are in this format say 2013-11-20 09:39:25.000001.
So i used the date datatype while creating the table, copied it to HDFS using the unenclosed json and used the select * query to retrieve the columns, but I get the above error. To get the values we are creating the same table with string data type respectively instead of date and we are able to get the values .
Can you suggest a solution for this problem. This question may seem silly but I am pretty new to programming.
Date data type supports only format YYYY-­MM-­DD
Timestamps or VARCHAR data type you can be used rather than date data type.
Date data types do not exist in Hive. In fact the dates are treated as strings in Hive. Refer the below post
http://www.folkstalk.com/2011/11/date-functions-in-hive.html
EsriJsonSerDe (and GeoJsonSerDe) support for DATE and TIMETAMP type columns is added on Spatial-Framework-for-Hadoop master in git.
Alternately, you can try using org.openx.data.jsonserde.JsonSerDe or org.apache.hive.hcatalog.data.JsonSerDe (instead of EsriJsonSerDe - and with column type string rather than binary) together with UnenclosedEsriJsonInputFormat.
[disclosure: Spatial-Framework-for-Hadoop collaborator]

Sql server getdate() convert problem

Hey I have time column and datatype date.. default value is getdate() but this return format like 2011-04-24
but I want like 24.04.2011 How can I convert that format?
what is the value format?
Getdate() is a datetime. That has no specific format. If you want a specific format you must convert it into a varchar.
select convert(varchar(10),getdate(),104)
There's more info on the different conversion codes here.
An SQL Server date column does not have an associated format.
You can specify a format when converting a date to a varchar column. See the MSDN page for convert. From MSDN, 104 is mm.dd.yyyy, so you could:
select convert(varchar(12),getdate(),104)
This prints 24.04.2011.

Resources