How to Trim the Trailing Characters in T-SQL

How to Trim the Trailing Characters in T-SQL thumbnail
T-SQL RTRIM function allows users to trim character strings.

Microsoft SQL Server uses T-SQL language for performing queries over the SQL databases. The trailing spaces present in character data types of database tables for the adjustment to columns width. The "RTRIM" function of the SQL Server allows you to truncate all trailing space characters from the character strings. It removes trailing spaces to the last non-space character or to a single-space character for the strings that contain only space characters. By trimming the trailing characters from the string in a T-SQL query, you can create properly formatted database reports.

Instructions

    • 1

      Click "Start" in Windows, and then click "Microsoft SQL Management Console."

    • 2

      Enter the following SQL statements in the open window:

      DECLARE @string_to_trim varchar(60);

      SET @string_to_trim = 'Five spaces are after the period in this

      sentence. ';

      SELECT @string_to_trim + ' Next sentence.';

      SELECT RTRIM(@string_to_trim) + ' Next sentence.';

      GO

    • 3

      Click "File" followed by "Run" to trim trailing spaces in the "string_to_trim" string.

Related Searches:

References

  • Photo Credit Jupiterimages/Photos.com/Getty Images

Comments

You May Also Like

Related Ads

Featured