Link to home
Start Free TrialLog in
Avatar of jackjohnson44
jackjohnson44

asked on

sql server trim whole database

Is there a way to trim beginning and trailing spaces, tabs, and new lines from a whole db?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of jackjohnson44
jackjohnson44

ASKER

this did not work
select replace(replace(testcasename, char(13), ""), char(10), "")

It says
An object or column name is missing or empty
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
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
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