To trim spaces, you can make use of
LTRIM() and
RTRIM() functions
Check this complete article on trimming by my favorite, Pinal Dave.
SQL SERVER – 2008 – TRIM() Function – User Defined Function[
^]
Example:
For individual field trimming-
SELECT AIDNO,
(LTRIM(RTRIM(ALOANUMBER))) + LTRIM(RTRIM(AIDNO))) AS LOAM
FROM VLOANS
For the concatenated result trimming-
SELECT AIDNO,
LTRIM(RTRIM((ALOANUMBER + AIDNO))) AS LOAM
FROM VLOANS
Hope, it helps :)
Note: For SQL Server 2012/2014, there is a function exists,
TRIM() which does the same thing instead of using two functions.