A smart join with union

August 13, 2008 at 12:54 pm Leave a comment

SELECT m.MonthName, COALESCE(c.MonthCost, 0)
FROM CostTable c
RIGHT JOIN (
 SELECT 1 As MonthNumber, 'January' As MonthName
 UNION
 SELECT 2, 'February'
 UNION
 ...
 SELECT 3, 'December'
) m
ON m.MonthNumber = MONTH(c.[Month])
Advertisements

Entry filed under: Database. Tags: , , , , , , , , , , , , , , , , .

Sql insert in Csharp Sql fetch cursors

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


August 2008
M T W T F S S
« Jul   Sep »
 123
45678910
11121314151617
18192021222324
25262728293031

%d bloggers like this: