Selecting a null columns with conditons
ID Date Day Status
001 23/02/2009 Monday Appear
001 24/02/2009 Tuesday Appear
001 25/02/2009 Wednesday Appear
001 26/02/2009 Thursday Appear
001 27/02/2009 Friday null
001 28/02/2009 Saturday Appear
001 29/02/2009 Sunday null
002
...,
Query
Select ID, Date, Day, ISNull(Status, 'Holiday') from table1
The above query is appearing Status null column as Holiday for all the days but i want to display for Friday and Saturday only.
In Friday there is null column it should appear as Holiday In Saturday there is null column it should appear as Holiday
Expected Output
ID Date Day Status
001 23/02/2009 Monday Appear
001 24/02/2009 Tu开发者_开发问答esday Appear
001 25/02/2009 Wednesday Appear
001 26/02/2009 Thursday Appear
001 27/02/2009 Friday Holiday
001 28/02/2009 Saturday Appear
001 29/02/2009 Sunday null
002
...,
Just use a case statement.
select ID, Date, Day,
ISNull(Status, case when Day not in ('Saturday', 'Sunday') then 'Holiday' end)
from table1
精彩评论