Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / T-SQL

LTRIM RTRIM doesn’t always work

3.00/5 (1 vote)
16 Feb 2012CPOL 13.3K  
In SQL Server 2008, I do that with a CLR User Defined Function:namespace PIEBALD.Lib{ public static partial class LibSql { public static string Trim ( string Victim ) { return ( Victim.Trim() ) ; } }}Needs to be built into a...
In SQL Server 2008, I do that with a CLR User Defined Function:

namespace PIEBALD.Lib
{
  public static partial class LibSql
  {
    public static string
    Trim
    (
      string Victim
    )
    {
      return ( Victim.Trim() ) ;
    }
  }
}


Needs to be built into a strongly-named Assembly and added to the GAC.

CREATE ASSEMBLY Library FROM 'C:\bin\Library.Sql.dll'
GO

CREATE FUNCTION dbo.Trim(@Victim NVARCHAR(MAX)) RETURNS NVARCHAR(MAX)
AS EXTERNAL NAME Library.[PIEBALD.Lib.LibSql].Trim;
GO

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)