Saturday, July 24, 2010

Get Month Name

Month Name in c#/VB.Net (August)

DateTimeFormatInfo.GetMonthName Method

s
tring strMonth = DateTime.Now.ToString("MMMM")

For the default invariant DateTimeFormatInfo, this method returns a string from the GregorianCalendar:
monthReturn Value
1"January"
2"February"
3"March"
4"April"
5"May"
6"June"
7"July"
8"August"
9"September"
10"October"
11"November"
12"December"
13""

Calendar objects can accommodate calendars with 13 months. For 12-month calendars, the empty string is always returned as the name of the 13th month.


Reff: http://msdn.microsoft.com/en-us/library/d4009dd5%28vs.71%29.aspx

Thursday, July 15, 2010

Counting Parents and Children with Count Distinct

The aggregate functions in SQL Server (min, max, sum, count, average, etc.) are great tools for reporting and business analysis. But sometimes, you need to tweak them just a little bit to get exactly the results you need. For example, if your manager came to you and asked for a report on how many sales have been made to your clients and how large they were, would you know how to get the data you need efficiently? Mark ran into something like this recently and here's the approach he took to solve the problem.

A typical, simple table structure for tracking sales orders includes a Customer table with name and address information, an OrderHeader table with the Customer's ID, Order Date and other details about the order as a whole, and an OrderDetail table with the detail line items for the order. To simplify our example, we will eliminate the separate Customer table and just focus on the OrderHeader and OrderDetail tables.