How to Trim in MS SQL


Most programming languages have a trim function, which removes any blank spaces before and after a variable's text. Microsoft (MS) SQL does not have a trim function, but it has rtrim and ltrim functions. These functions remove spaces from the right and left side of the variable text. You use these functions in place of other languages' trim function.

  • Click the Windows "Start" button and select "All Programs." Click "SQL Server," then click "SQL Server Management Studio." This opens the MS SQL application for your database server.

  • Click the "Programmability" icon, then click "Stored Procedures." Right-click the stored procedure you want to edit and select "Modify."

  • Add the rtrim and ltrim functions to the variables you want to trim. You can embed both functions. For instance, the following code inserts a name into the customer table and removes any trailing or prefix blank spaces:

    insert into customer (name) values (ltrim (rtrim (' Joe ')))

    In this example, the name "Joe" has spaces trimmed, so the value inserted into the database is "Joe" and not " Joe ."

  • Press "F5" to execute the code and save the stored procedure changes. Close the opened SQL editor to close the stored procedure code.

Related Searches


Promoted By Zergnet


You May Also Like

  • How to Convert an Int to a String in T-SQL

    Microsoft created T-SQL, or "Transact-Standard Query Language," to allow programmers to access, modify and delete database data. You can use T-SQL in...

  • How to Use Excel's TRIM Function

    Excel's TRIM function removes all spaces from the specified text except a single space between words. It is frequently used on text...

  • How to Remove Leading Zeros in SQL

    SQL allows the programmer to store data from any form of document, even images and rich media, directly within the server. The...

  • How to Remove Space From a Data Oracle SQL

    There are several different methods for removing spaces from data retrieved in an Oracle results set. Oracle PL/SQL provides several different character...

  • How to Remove Blank Spaces in SQL

    In the programming world, it's important that data entered by users be validated. Users commonly enter data through text boxes, list boxes...

  • How to Trim in T-SQL

    T-SQL (Transact SQL) is the proprietary language used by Microsoft SQL Server. It is an extension of the SQL (Structured Query Language)...

  • How to Trim Leading Spaces in Text in Microsoft Access

    Whether you've populated your Access tables by typing, pasting or importing text into them, those tables might contain leading spaces and other...

  • String Functions in Oracle SQL

    String functions in an Oracle database system can perform many different tasks, and developers often make use of SQL string functions regardless...

  • How to Use Excel's TRIM Function

    Excel's TRIM function will clear off any spaces that are within a cell and surrounding the data on both sides. Use Excel's...

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!