Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home SQL Server MSSQL Trim Function

MSSQL Trim Function

Trim() function is very popular function in many programming or sql languages which can delete leading or trailing spaces of any string. But Microsoft SQL Server does not support the function, so sad!

However, MS SQL Server has LTRIM() and RTRIM() functions which can delete leading and trailing respectively.

Example will show how to trim your string in MSSQL Server, it should works in 2000, 2005 and 2008 version

[sql] declare @str varchar(50)
set @str = ‘ ms sql trim function ‘
print @str
print ltrim(rtrim(@str))
[/sql]

Output:

[text] ms sql trim function
ms sql trim function
[/text]

Or you can implement a TRIM() function for your MS SQL Server database as below:

+ SQL Server 2000:

[sql] create function dbo.trim(@string varchar(8000))
returns varchar(8000)
begin
return ltrim(rtrim(@string))
end
[/sql]

+ SQL Server 2005 and SQL Server 2008:

[sql] create function dbo.trim(@string varchar(max))
returns varchar(max)
begin
return ltrim(rtrim(@string))
end
[/sql]

After that, run SQL script below to test:

[sql] declare @str varchar(50)
set @str = ‘ ms sql trim function ‘
select dbo.trim(@str)
[/sql]
Mar 24, 2011Hoan Huynh
Excerpt box disappeared on Wordpress New VersionTop Free Real Time Website Analytics Services And Tools
You Might Also Like:
  • Javascript LTrim,RTrim,Trim function
  • MSSQL Split Function returns table data
  • MSSQL Split String Function
  • Replace String With NText Or Text Data Type In MS SQL Server
  • How To Track Website With Multiple Google Analytisc Accounts
  • Simple Truncate Words Function In C#
  • Truncate And Limit Displayed Text With Selected Maximum Length PHP Function
  • String To Upper Case In PHP, JavaScript And .Net (CSharp)
  • String To Lower Case In PHP, JavaScript And .Net (CSharp)
  • C# Get File Extension Without Sub String Or Split Function
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

10 years ago SQL ServerLTRIM, Microsoft, RTRIM, SQL, Trim363
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
22,167 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
20,044 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,824 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,306 views
C# Read Json From URL And Parse/Deserialize Json
9,794 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • How to Compose Your Essay To Me – 4 Easy Steps to Write My Essay
  • How to Find a Photo Editor
  • Installment Loans – Making Sense of Online Software
  • Apple Pay Casino Canada
  • Casinos austria
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (28)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (105)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development