Search code examples
sqlderby

How to return a NULL value for Date type column in SQL in Derby?


In my Sql, I want to group by some columns having some conditions , so for other column, they are date type. I just want to manually return null for them, But i don't know how. Can you give me some advice how to return null for date type column? To simply use NULL doesn't work in Apache Derby which is odd.

I am also interested in the answer for other database. If you can also answer it, it will be great.

EDIT

Reply to comment, I want select NULL from TABLE, and NULL stands for an empty value of DATE type column. I just want to return a NULL value manually.But it throws exception tells me NULL is invalid. Is that possible?

EDIT

I found an workaround to return a constant value for date type in Derby. That is using Date(789) which is date function in derby. But I am still insterested in how to return an empty constant value for Date?

EDIT

NULL in query in Derby must be casted to correct type. which is a bit different.


Solution

  • It should use cast(null as DATE) AS START_DATE expression. As in the link.

    I just add here for others to find it out easily. One thing interesting is even the column START_DATE is NOT NULL, I can still fake a NULL return value for this column. Actually it should be , not a surprise at all here,right?