Johnson Gale
Johnson Gale

Reputation: 165

Oracle SQL | Making a date field from two separate fields

How would I make a single date field using these two fields?

So if I had a table with this:

MONTH        YEAR
2            2013
4            2012
2            2012

How would I combine the month and the year to make a field in that looks like this...

DATE
2013-02
2012-04
2012-02

Upvotes: 0

Views: 34

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270021

In Oracle, I would just use concatenation and lpad():

select (year || '-' || lpad(month, 2, '0') ) as date

Upvotes: 1

Related Questions