I have problems with comparing the day of week
Here is my query in oracle database.
SELECT DAY, WEEKDAY
FROM (SELECT v.TNI, v.FRMP, v.LR, v.DAY, v.HH, v.VOLUME,
CASE WHEN hd.HOLIDAY_DATE is not null then 'HOLIDAY'
ELSE to_char(v.DAY, 'Day') END AS WEEKDAY
FROM v_nem_rm16 v
LEFT JOIN DBP_ADMIN.DBP_HOLIDAY hd
ON v.DAY = hd.HOLIDAY_DATE
WHERE v.STATEMENT_TYPE != 'FORECAST')
WHERE WEEKDAY = 'Monday';
Basically, the "WEEKDAY" column has the day of week based on the "DAY". Day is just date like 13/Mar/17
If you look at the "CASE" statement, you will notice that the "WEEKDAY" column is filled by "to_char(v.DAY, 'Day')".
So the column has values like "Sunday, Saturday and so on, the day of week".
The problem is the outer query's where clause, "WHERE WEEKDAY = 'Monday'"
When I execute this query, It does not give me any rows even if I have rows having Monday as the value in "WEEKDAY" column
But when I change the WHERE clause to "WHERE WEEKDAY = to_char(sysdate, 'Day')", It works fine. The sql statement gives me the rows having "Saturday" in "WEEKDAY" column since the "to_char(sysdate, 'Day')" gives me "Saturday".
So what is problems with my first query??
I just want to filter rows by the name of the day of week like if i pass "Monday", i want to have all the rows having " Monday" in "WEEKDAY" column.
How can I do??
THANKS GUYS
to_char(v.DAY, 'fmDay')
. Be aware, result depends on current sessionNLS_DATE_LANGUAGE
value which may change at any time. – Wernfried Domscheit