How to use a TRIM function in SQL Server

user1958651 picture user1958651 · Jan 21, 2013 · Viewed 271.5k times · Source

I cannot get this TRIM code to work

SELECT 
   dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR AS [EHP Code], 
   dbo.COL_TBL_VCOURSE.TNG_NA AS [Course Title], 
   LTRIM(RTRIM(FCT_TYP_CD)& ') AND (' & LTRIM(RTRIM(DEP_TYP_ID) & ')' AS [Course Owner]

Answer

maelstrom picture maelstrom · Jan 21, 2013

You are missing two closing parentheses...and I am not sure an ampersand works as a string concatenation operator. Try '+'

SELECT dbo.COL_V_Cost_GEMS_Detail.TNG_SYS_NR AS [EHP Code], 
dbo.COL_TBL_VCOURSE.TNG_NA AS [Course Title], 
LTRIM(RTRIM(FCT_TYP_CD)) + ') AND (' + LTRIM(RTRIM(DEP_TYP_ID)) + ')' AS [Course Owner]