How to list all user defined functions in MSSQL

To list all user defined functions in MSSQL you can use the following snippet.

Sample MSSQL

SELECT name AS function_name, SCHEMA_NAME(schema_id) AS SCHEMA_NAME ,type_desc FROM sys.objects WHERE type_desc LIKE '%FUNCTION%' ORDER BY name asc;

ChangeEncoding extension method for C# and VB.NET

This snippet will give you the ChangeEncoding extension method for C# and VB.NET.

Sample C#

public static string ChangeEncoding(this string input, Encoding encoding)
{
	var bytes = encoding.GetBytes(input);
	return encoding.GetString(bytes);
}

Sample VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Function ChangeEncoding(input As String, encoding As Encoding) As String
	Dim bytes = encoding.GetBytes(input)
	Return encoding.GetString(bytes)
End Function

OpenIfClosed DBConnection extension method for C# and VB.NET

This snippet will allow you to use the OpenIfClosed DBConnection extension method for C# and VB.NET.

Sample C#

public static void OpenIfClosed(this DbConnection connection)
{
	if (connection!=null && connection.ConnectionString!=String.Empty && connection.State == ConnectionState.Closed)
	{
		connection.Open();
	}
}

Sample VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Sub OpenIfClosed(connection As DbConnection)
	If connection IsNot Nothing AndAlso connection.ConnectionString <> String.Empty AndAlso connection.State = ConnectionState.Closed Then
		connection.Open()
	End If
End Sub

Pad functions for Javascript

This snippet will give you the pad functions (padRight, padLeft) for javascript.

Sample Javascript

String.prototype.padLeft = function(length, character) {
	var text = this.valueOf();
	var character = character || " ";
	while (text.length<length) {
		text = character + text;
	}
	return text;
};

String.prototype.padRight = function(length, character) {
	var text = this.valueOf();
	var character = character || " ";
	while (text.length<length) {
		text = text + character;
	}
	return text;
};