0
votes

I want to restrict the rows I retrieve by using 'between' for two dates.

The 'saledate' column I used has the following infomation

SALEDATE DATE FORMAT 'YYYY-MM-DD' NOT NULL

The code I used:

SELECT *
FROM trnsact
WHERE saledate BETWEEN '2005-01-01' AND '2005-06-30';

And then I got an error 'Error Code - 3535 Error Message - [Teradata Database] [TeraJDBC 15.10.00.09] [Error 3535][SQLState 22003] A character string failed conversion to a numeric value.'

I also tried with DATE:

SELECT *
FROM trnsact
WHERE saledate BETWEEN DATE '2005-01-01' AND DATE '2005-06-30';

But end up with another error Error Message - [Teradata Database] [TeraJDBC 15.10.00.09] [Error 3706] [SQLState 42000] Syntax error: Invalid DATE Literal.

Thanks for your help

2
Those date literals are fully valid, can you try a simple `SELECT DATE '2005-01-01', DATE '2005-06-30;'? - dnoeth

2 Answers

1
votes

You need to use DATE literals:

SELECT *
FROM trnsact
WHERE saledate BETWEEN DATE '2005-01-01' AND DATE '2005-06-31';
0
votes

try below query for teradata. It's too late though.

SELECT *
FROM trnsact
WHERE saledate BETWEEN 
    to_date('2005-01-01','YYYY-MM-DD') AND 
    to_date('2005-06-30','YYYY-MM-DD') ;