DB2 simple date comparison - sql

I have two column with date type in table.
Now my objective is to extract all rows where this two column having different value.
Something as below:
Select * from tableA where dateColA != dateColB;
But I get SQL0181 Value in date, time, or timestamp string not valid

Related

AWS Athena query to find Date column has String or not satisfying timestamp format

I was testing Sprak 3 upgrades in AWS Athena and need to check date columns whether timestamp format is proper or not,Can any one please give me query to check whether date columns has any Values other than Timestamp format
Assuming that you have a varchar column you can try using date_parse wrapped in try:
select *
from table
where try(date_parse(string_column, 'your_expected_format')) is null -- assuming no original nulls in column
Or via try_cast for "standard" format:
select *
from table
where try_cast(string_column as timestamp) -- assuming no original nulls in column

Find most recent date in a table using HIVE

I just need to make a simple query of a table on a MapR cluster in that I want to know what the date is of the most recent record in the table. Dates are in a 'report_date' column in string format. I tried the following query without success:
select max(report_date) from partition.table_name
I know the second part of the statement works. Is there something wrong with the first part?
Thanks,
A
Your date column datatype is string hence the max function doesnt produce the output as desired.
for example : string column with values 1,2,3,4 and when you run max(column) you wont get the output as 4 , since max doesnt work on string datatype.
Try changing your datatype to DATE or TIMESTAMP , Which should work.
OR
if changing datatype is not possible then try,
If there is an auto incrementing ID column in the table or any column like so , then
select report_date from table_name order by ID desc.
This should provide you the max date sting.

Oracle compare number date between two dates

I have a field with the data type of number which represents a date
eg: 20060421
I have two other fields in other table with the data type of Date.
I want to retrieve the rows from the first table that lies between those two Dates present in the other table.
How Can I compare the date in simple number format in a between clause of two Dates of data type Date.
I think the simplest solution for you here is to just cast the numeric date into a date type and then just use the built-in BETWEEN function.
-- sample cast
select to_date(to_char(20060801),'YYYYMMDD') from dual
so your solution should look something like this:
select *
from numericDatesTable t1, otherTable t2
where to_date(to_char(t1.date),'YYYYMMDD') between t2.date1 and t2.date2

SQL newbie: Use current date as variable in SQL query

I have used Excel and created 2 columns. column1 contains DATES, column2 contains values as INT. I have imported the table as a CSV using SQLite Manager. I am connected to the DB and have used it with success for other queries that involved text only. Now I would like to SELECT the INT in column2 that corresponds to the current date displayed in column1. Therefore, everyday when the SQL query is ran it will auto-update based on the new current date. I have used
SELECT column2 FROM table WHERE column1 = CURRENT_DATE
However, it returns null (blank, nothing), whereas if I use
SELECT column2 FROM table WHERE column1 > CURRENT_DATE
it returns the INT in column2 of rowid1, but if I use
SELECT column2 FROM table WHERE column1 < CURRENT_DATE
it returns the INT in column 2 of rowid3.
Therefore, the DB is functioning; however, the problem is it cannot associate the current system date with the right value in column1. Is it possible that the import of CSV. into SQLite has altered the datatype to VARCHAR or something other than DATE and INT?
SQLite does not have a DATE data type.
Dates are typically stored as strings (CSV does not have types anyway), and to be compatible with SQLite's built-in date functions, must be in the format yyyy-mm-dd.
Before exporting from Excel, ensure that all dates are formatted with this format.

Query to fetch records from a table, for a particular date if the date column is in date data type

Query to fetch records from a table, for a particular date if the date column is in DATE data type.
Iam working in DB2.
if i give data format in 03/06/2011(mm/dd/YYYY)
ex:
Select * from table customer where date = "03/06/2011" is not working. date column is DATE data type.
Change double quotes to single quotes, maybe?
Select * from table customer where date = '03/06/2011'
Also, using ISO format to specify a date value might be more reliable:
Select * from table customer where date = '2011-03-06'
I think you need to convert your string date to an actual Date, like this:
Select * from table customer where date = DATE('03/06/2011');