Hi All,
I have one query in SQL server. I want to convert that query to Oracle. Well i am not that good with writing queries in Oracle. Please help. Following is the query in SQL server.
DECLARE @StartYear AS INT = 2010;
DECLARE @EndYear AS INT = 2014;
WITH
years
AS (SELECT YYYY = @StartYear
UNION ALL
SELECT yyyy + 1
FROM years
WHERE yyyy < @EndYear)
,months
AS (SELECT MM = 1
UNION ALL
SELECT mm + 1
FROM months
WHERE mm < 12)
,days
AS (SELECT DD = 1
UNION ALL
SELECT dd + 1
FROM days
WHERE dd < 31)
,datesraw
AS (SELECT YYYY = yyyy,
MM = mm,
DD = dd,
ID_Date = yyyy * 10000 + mm * 100 + dd,
Date = CASE
WHEN Isdate(yyyy * 10000 + mm * 100 + dd) = 1 THEN Cast
( Cast(yyyy * 10000 + mm * 100 + dd AS VARCHAR) AS DATE)
ELSE NULL
END
FROM years
CROSS JOIN months
CROSS JOIN days
WHERE Isdate(yyyy * 10000 + mm * 100 + dd) = 1)
SELECT d.id_date,
d.date,
[Year] = Year(d.date),
MonthNumber = Month(d.date),
[Month] = Datename(month, d.date),
DayOfMonth = Day(d.date),
DayOfWeekNumber = Datepart(dw, d.date),
[DayOfWeek] = Datename(dw, d.date),
WorkingDay = Cast(CASE Datepart(dw, d.date)
WHEN 1 THEN 0
WHEN 7 THEN 0
ELSE 1
END AS BIT)
FROM datesraw d
ORDER BY d.date
Which Gives output in following format.
id_date date Year MonthNumber Month DayOfMonth DayOfWeekNumber DayOfWeek WorkingDay
20100101 1/1/2010 2010 1 January 1 6 Friday 1
20100102 1/2/2010 2010 1 January 2 7 Saturday 0
20100103 1/3/2010 2010 1 January 3 1 Sunday 0
20100104 1/4/2010 2010 1 January 4 2 Monday 1
20100105 1/5/2010 2010 1 January 5 3 Tuesday 1
Thanks in Advance