Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql teradata filtering on date - database version Teradata 15.10.06.02 and provider version Teradata.Net 15.11.0.0

my table has a date column. its data type is date. I confirmed it by going to table name>>columns and it says MTH_END_DT [DATE, Not NULL]

I want to filter my data for a particular date. If I put a condition where MTH_END_DT = '6/1/2018' I get an error select failed [3535] A character string failed conversion to a numeric value.

I followed this page. I used where MTH_END_DT = date '6/1/2018' and i get an error syntax error invalid date literal

I tried where cast(timestamp_column as date) = date '2013-10-22'; something like this and it throws error too

How should i filter my data?

like image 927
Ni_Tempe Avatar asked Jun 15 '18 18:06

Ni_Tempe


People also ask

What is .NET Data Provider for Teradata?

NET Data Provider for Teradata is an implementation of the Microsoft ADO.NET specification. It provides direct access to the Teradata Database and integrates with the DataSet. . NET Applications use the . NET Data Provider for Teradata to load data into the Teradata Database or retrieve data from the Teradata Database.

How do I query a date in Teradata?

In Teradata, we can fetch the current date using either CURRENT_DATE or DATE in the Select statement. Both of the build functions returns Current/Today's date. The format of the date is 'YYYY-MM-DD' as below.

How do I list all databases in Teradata?

As @dnoeth mentioned, you can get a list of databases by querying the DBC. databasesV table. If you want to also see the hierarchy, you can see the OwnerName in that table and create the hierarchy from that parent/child relationship.


2 Answers

There's only one reliable way to write a date, using a date literal, date 'yyyy-mm-dd'

where MTH_END_DT = DATE '2018-06-01'

For a Timestamp it's

TIMESTAMP '2018-06-01 15:34:56'

and for Time

TIME '15:34:56'

In SQL Assistant it's recommended to switch to Standard SQL format YYYY-MM-DD in Tools-Options-Data Format-Display dates in this format

like image 184
dnoeth Avatar answered Sep 19 '22 10:09

dnoeth


I did have the similar problem when I was filtering a particular date for my query with Teradata. First method I tried was putting 'DATE' term as the following:

WHERE saledate = DATE'04/08/01' but this did not solve the problem.

I then used an approach I stumbled upon when surfing, finally it worked.

WHERE extract(year from saledate)=2004 AND extract(MONTH from saledate)=8 AND extract(DAY from saledate)= 1 source

I think this really should not be this long, but it worked.

like image 44
Ozkan Serttas Avatar answered Sep 21 '22 10:09

Ozkan Serttas