Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 TRIM function and the || concatenation operators

Author  Topic 

nguyenl
Posting Yak Master

128 Posts

Posted - 2008-08-01 : 17:13:13
Is there a way to write these TRIM function and the || concatenation operators. For example, TRIM(section) || '-' || TRIM(township) || '-' ||TRIM(range), so that it would work in SQL?



select prop_type,
TRIM(section) || '-' || TRIM(township) || '-' ||TRIM(range),
nbhd,
region,
inspct_cycle,
water,
sewer_septic,
unimproved_acres,
improved_acres,
total_sqft from parcel,
legal_description

where legal_description.property_id = [PROPERTYID]
and parcel.property_id = [PROPERTYID]
and parcel_year = 2008

Please help.

Thanks,

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-08-01 : 17:15:33
RTRIM(section) + '-' + RTRIM(township) + '-' + RTRIM(range),


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-02 : 05:25:42
quote:
Originally posted by jhocutt

COALESCE(RTRIM(section) + '-','') + COALESCE(RTRIM(township) + '-','') + COALESCE(RTRIM(range),''),


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking


and also account for NULL values just in case the columns are nullable
Go to Top of Page
   

- Advertisement -