I am selecting dates from a database, With a typical result of four seperate dates.
However sometime a date is missing and only returns 3 dates.Im am using C#, asp.net.
Example one:
2010-04-01 00:00:00.000, 2010-05-01 00:00:00.000, 2010-06-01 00:00:00.000, 2010-07-01 00:00:00.000
Example 2:
2010-04-01 00:00:00.000, 2010-05-01 00:00:00.000, 2010-07-01 00:00:00.000
I want it so that this result is displayed in a Database and the missing month has a message which takes up the row with a message like “No entry”.
Desired:
2010-04-01 00:00:00.000, 2010-05-01 00:00:00.000, No Entry, 2010-07-01 00:00:00.000
Any ideas of how to do this?
I would do a right join with a complete result set (a result set that would always contain all the dates you need) and, if the data on the left is null, replace it with the text you need.
Something like this:
select case when x.date is not null then x.date else ‘No Entry’ end from
myTable x right join completeTable c on x.date = c.date