Solved

sql server trim whole database

Posted on 2007-11-29
7
950 Views
Last Modified: 2012-06-22
Is there a way to trim beginning and trailing spaces, tabs, and new lines from a whole db?
0
Comment
Question by:jackjohnson44
7 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 20375601
you can do that only per table, and per table, you have to specify all the columns where you want to perform that operation.

the triming can be done with the function TRIM(), and the newline would be removed using the REPLACE() funciton:

UPDATE yourtable
  SET yourfield = trim(replace(replace(yourfield, char(13), ""), char(10), ""))
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 200 total points
ID: 20375607
to trim leading and trailing spaces,just use
Trim(string)
or trim([fieldName])

to remove new lies and carriage return use Replace function

Repalce(Replace(xstring,chr(10),""),chr(13),"")
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 20375638
Easiest way I can think of off hand would be to write a simple function to search for and trim said characters and then....
Link all tables to an Access Database via an ODBC connection then...
Cycle thru all of the linked tables, fields and records and trim all the fields found in every record from every table.  

Depending on how much data you're talking about it may take some time but once started the process could be left to simply run till it is done.  To speed things up it would probably make sense for the function to consider only text and memo fields in the process (why fiddle with that that need not be reviewed).  

Would that solution be acceptable for you?

Rick
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:jackjohnson44
ID: 20375667
this did not work
select replace(replace(testcasename, char(13), ""), char(10), "")

It says
An object or column name is missing or empty
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 20375867
select replace(replace(testcasename, char(13), ""), char(10), "") from nameoftable

change { testcasename } withe name of the field from the table
change { nameoftable } with the actual name of the table
0
 
LVL 16

Expert Comment

by:Rick_Rickards
ID: 20378817
Hey Jack,

Are you willing to let Access resolve this for you?  You'll need an ODBC connection, (not hard to do) and a copy of Access and a little code that I can help you with.  After that it's just a matter of linking all your tables, running the code and waiting for it to finish.  The elegance of this method is that it can easily sweep thru ever record, text field and table for you.  Admittedly I'm Access biased so if anyone can think of a way to get SQL server to do this I'm as eager as anyone to see it done, but absent any suggestions I know I can get Access to do what you're wanting done.

Rick
0
 
LVL 5

Expert Comment

by:ursangel
ID: 20380936
For trialing and beginning spaces you can use LTRIm()  and RTrim () functions and for tabs and new lines, you need to use the replace methods. But everything need to be done till the table level
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now