CLR integration – SQL

Just written my first C# SQL function, here it is in all its glory.

public static DateTime GetSunday(DateTime original)
    DateTime result
= new DateTime(original.Year, original.Month,
((int) original.DayOfWeek),
0, 0, 0);
return result;

Then I went and found out how to really go to town.…/sqlclrguidance.asp, so here is my 2nd function (and helper)


=Date datetime)]
public static IEnumerable GetAllDates(DateTime start, DateTime end)
    DateTime date = start.Date;
<DateTime> result = new List<DateTime>();
while (date <= end)
= date.AddDays(1);
return result;

public static void FillGetAllDates(object row, out DateTime date)
= (DateTime) row;


Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s