SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Remove spaces
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jfm
Posting Yak Master

134 Posts

Posted - 09/13/2012 :  12:53:25  Show Profile  Reply with Quote
Hi there,

I have an ID_Column. The matter is that the data is as follows:

AXBN- JT3

AXBN-JT3



I have some middle spaces in some cells. I need to remove those spaces, because SQL is recognizing the cells as a different one, due to that middle space.

Anyone knows any query to remove it?

Many thanks

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 09/13/2012 :  12:56:33  Show Profile  Visit tkizer's Homepage  Reply with Quote
Use the replace function to remove the spaces.

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

Subscribe to my blog
Go to Top of Page

jfm
Posting Yak Master

134 Posts

Posted - 09/13/2012 :  13:02:40  Show Profile  Reply with Quote
How you will write the query?

Using Monthly_Table and Mydatabase.

Regards
Go to Top of Page

jfm
Posting Yak Master

134 Posts

Posted - 09/13/2012 :  13:06:18  Show Profile  Reply with Quote
I used the following query to remove the left and right spaces. But i cant remove the middle ones:

UPDATE table
SET ax = replace ( ax, ax, RTRIM(ltrim( ax)))
where ax <>''

Thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 09/13/2012 :  13:18:23  Show Profile  Visit tkizer's Homepage  Reply with Quote
Why did you add RTRIM/LTRIM to the query?

UPDATE t1
SET c1 = REPLACE(c1, ' ', '')

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

Subscribe to my blog
Go to Top of Page

jfm
Posting Yak Master

134 Posts

Posted - 09/13/2012 :  13:32:16  Show Profile  Reply with Quote
Perfect.

I used them, because, I'd take info from other columns and they had spaces too.

Thanks!
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 09/13/2012 :  13:41:03  Show Profile  Visit tkizer's Homepage  Reply with Quote
What I posted doesn't require RTRIM/LTRIM at all. It removes ALL spaces from that column, regardless of where they are.

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

Subscribe to my blog
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000