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 2008 Forums
 Transact-SQL (2008)
 Trim Function

Author  Topic 

jscot
Posting Yak Master

106 Posts

Posted - 2011-02-26 : 21:12:01
Hi Guys,

I have question regarding Trim function,
Here is my requirement,

Address = ADDRESS1+ADDRESS2+ADDRESS3

I want to trim if there is no Address1 or Address3

I know i can use Ltrim & Rtrim function, Could you please anyone can help me how i can use trim function in TSql and SSIS. Thanks in advance.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-02-27 : 00:09:50
If there aren't values for Address1 and/or Address3, will they be NULL, the empty string, or something else?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jscot
Posting Yak Master

106 Posts

Posted - 2011-02-27 : 00:40:19
i am using ISNULL function, if there is Null convert to "Blank" so i want to remove empty spaces.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-02-27 : 03:51:06
quote:
Originally posted by jscot

i am using ISNULL function, if there is Null convert to "Blank" so i want to remove empty spaces.



can you show us your query on the isnull() ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mandm
Posting Yak Master

120 Posts

Posted - 2011-02-28 : 16:27:45
When you say you're converting isnull to blank do you mean a single space as in ' '? If so why not just convert it to empty string instead? Then you don't need to worry about trimming the spaces.
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-03-01 : 10:32:51
1) You dont need to Trim the addresses if there are NULL Values in them .. simply use Address = isNULL(ADDRESS1,'')+isNULL(ADDRESS2,'')+isNull(ADDRESS3,'')

2) if there are chances of leading/trailing spaces in the Address columns then you can use: Address=isnull(ltrim(rtrim(address1)),'')+isnull(ltrim(rtrim(address2)),'')+isnull(ltrim(rtrim(address3)),'')



Cheers
MIK
Go to Top of Page
   

- Advertisement -