Here is something I do alot when I find that I am going to be replicating a task. I create a function that does the task that I will be repeating. In your case it would be something like this:
CREATE FUNCTION dbo.Trim (@tempString varchar(8000))
IF @tempString IS NOT NULL
IF LEN(@tempString) > 0
To test this just go to query analyzer and type this:
DECLARE @T1 CHAR(10)
DECLARE @T2 VARCHAR(10)
SET @T1 = ' test ' -- 3 leading spaces, test, and 3 trailing spaces
SET @T2 = dbo.trim(@T1)
You should see the first string reads 10 characters long and prints with all 10 characters. The second set of statements should read 4 characters long and print with only 4 characters.
This can also be done directly in your SELECT statements, such as:
SELECT dbo.Trim(fieldname) FROM tablename
When done from the SELECT statement implicit conversion takes places so you don't have to cast or convert these values to anything other than what they are.