Tuesday, September 16, 2014

Querying a DATE field and a TIMESTAMP

When I was running a few reports, I faced a very interesting scenario.
(Because I'm lazy I wrote a Stored Proc with all my queries and used a scheduled Job to run it)

Anyway, the idea here is that I had to run my report for a certain window of time.
So I declared my start date and end date variables as DATE and wrote all my queries using: And when I ran for the first time my queries in the body of the Stored Proc I got a bunch of errors. Why???

After thinking seriously, that maybe I've lost my edge I just realized that in a few tables the created_on column was declared as DATE and in others as TIMESTAMP. Not the end of the world, I just decided to change the data type of my variables to TIMESTAMP and end of the story :)