How to TRIM a string in MSSQL

To TRIM a string in MSSQL you can use the following Userdefinedfunction Snippet.

Sample MSSQL

CREATE FUNCTION dbo.TRIM(@inputString VARCHAR(MAX))
RETURNS VARCHAR(MAX)
BEGIN
RETURN LTRIM(RTRIM(@inputString))
END

Trim functions for Javascript

This snippet will give you the Trim functions for Javascript.

Sample Javascript

String.prototype.ltrim = function () {
    return this.replace(/^\s+/, '');
}

String.prototype.rtrim = function () {
    return this.replace(/\s+$/, '');
}

String.prototype.trim = function () {
    return this.ltrim().rtrim();
}