Solved

sql server trim whole database

Posted on 2007-11-29
7
940 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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

759 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

20 Experts available now in Live!

Get 1:1 Help Now