Archive

Archive for April, 2009

Simple way to create a singleton

April 28th, 2009 No comments

Found this is microsoft official line on creating a singleton, much simpler than the normal GOF way :)

// .NET Singleton
sealed class Singleton
{
private Singleton() {}
public static readonly Singleton Instance = new Singleton();
}

Categories: .net, c# Tags:

Getting Midnight in SQL

April 16th, 2009 No comments

Just a little udf that gets midnight for a datetime.

CREATE FUNCTION dbo.Midnight (@Date datetime)
RETURNS Datetime AS
BEGIN
	return CAST(FLOOR(CAST(@Date AS FLOAT)) AS DATETIME)
END
Categories: SQL Tags:

Parse Paths in SQL

April 16th, 2009 No comments

Just a couple of udf to handle paths in sql server, not very solid but if your paths are valid they work well.

CREATE FUNCTION dbo.GetFileName (@Path varchar(512))
RETURNS varchar(255) AS
BEGIN
	Return    RIGHT(@Path, LEN(@Path) - dbo.LAST_INDEX(@Path, '\'))
END

Read more…

Categories: SQL Tags: