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)
 Compare string with trim multiple spaces

Author  Topic 

keyursoni85
Posting Yak Master

233 Posts

Posted - 2011-04-15 : 03:51:09
Hi,

I have two type of data in different tables as

ColumnA ColumnB
18, Sas Garden 385748 18, Sas Garden 385748


I need to compare above data and those data should be equal..
Can anyone help me in above situation

Space will occur more than one but i need to consider only one

Thank you in advance..

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-04-15 : 04:09:10
[code]
declare @ColumnA varchar(255)
declare @ColumnB varchar(255)
set @ColumnA = '18, Sas Garden 385748'
set @ColumnB = '18, Sas Garden 385748'

select
@ColumnA,
@ColumnB
where @ColumnA <> @ColumnB

select
@ColumnA,
@ColumnB,
replace(replace(replace(@ColumnA,' ','~# '),' ~#',''),'~#',''),
replace(replace(replace(@ColumnB,' ','~# '),' ~#',''),'~#','')
where replace(replace(replace(@ColumnA,' ','~# '),' ~#',''),'~#','') = replace(replace(replace(@ColumnB,' ','~# '),' ~#',''),'~#','')
[/code]


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

keyursoni85
Posting Yak Master

233 Posts

Posted - 2011-04-15 : 05:22:40
Thank you webfred..
:)
Go to Top of Page
   

- Advertisement -