x
login about faq Site discussion (meta-askssc)

Space issue in data

i am joining two tables based on column comm. but in both the tables there is a data problem with spaces like "010 - aaaa > 9'" and in another table "010 - aaaa > 9'". How to get rid of extra space after 010 while joining.

more ▼

asked Aug 27 '12 at 04:09 PM in Default

Mohan gravatar image

Mohan
314 17 30 42

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

You can specify more than just a column name on either side of a JOIN clause, eg:

SELECT * 
FROM foo 
LEFT JOIN bar ON foo.SomeString = REPLACE(bar.SomeString, ' ', '')

However, performance will not be so good.

more ▼

answered Aug 27 '12 at 04:39 PM

ThomasRushton gravatar image

ThomasRushton ♦
29.1k 6 9 36

Replacing all the spaces from only one side may not yield the correct results. So my preference would be replacing all the spaces on both sides and also do a FULL OUTER JOIN to see all the non-matching values. But +1 for the core idea though :)

Aug 28 '12 at 01:53 PM Usman Butt
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x912

asked: Aug 27 '12 at 04:09 PM

Seen: 261 times

Last Updated: Aug 28 '12 at 01:53 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.