473,394 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Replace chars in any field of a table

I need to strip some puntcuation from any field in a given table.
I'd rather like to avoid using the replace () for each field in the
table.
Anyone have a nifty way do this?
Is there a special name that I can use in the replace that means the
entire row?
(other than syntax, something like REPLACE(@ROW,CHAR(39),'') )
tia
Rob

Feb 1 '06 #1
1 1343
You could try the following. It uses a cursor, which I'm sure is a bad
thing. But it should work. I didn't try it out. The cursor grabs
column names for columns that are of a varchar type. That may not be
what you need. But the Replace function requires a string, so there ya
go. Maybe (most likely) someone will have a better way to do this.
Hope it helps.

Jennifer

Declare @Tbl nvarchar(100)
Declare @Qry nvarchar(1000)
Declare @N nvarchar(100)

Set @Tbl = 'TableName'

DECLARE col_cursor CURSOR FOR
select name
from syscolumns
where id = object_id(@Tbl)
and xtype = 167
order by colid

OPEN col_cursor
FETCH NEXT FROM col_cursor into @N

WHILE @@FETCH_STATUS = 0
BEGIN
Set @Qry = 'Update ' + @Tbl + ' Set ' + @N + ' = REPLACE (' + @N +
', ''-'' , '''')'
EXEC sp_executesql @Qry
FETCH NEXT FROM col_cursor into @N
END

CLOSE col_cursor
DEALLOCATE col_cursor

Feb 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Zack Sessions | last post by:
I have a table that has a Text datatype column that has gotten some garbage characters in it somehow, probably from key entry. I need to remove the garbage, multiple occurances of char(15). The...
2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
2
by: lesperancer | last post by:
I've read all the posts, but nothing works I've got a table with an ID field and a memo field one record in the table, with the memo field having 322 chars I open the table, and then use the...
7
by: gar | last post by:
Hi, I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code text= Replace(text, """", "'" This works fine (for normal double quotes).The problem...
1
by: Jeff | last post by:
A client showed me this one. In a totals query that counts items and links to a parent record, what should be the output from a memo field shows up as Chinese characters - I kid not. He has a...
5
by: Michele Petrazzo | last post by:
Hi, a lot of times I need to replace more than one char into a string, so I have to do something like value = "test" chars = "e" for c in chars: value = value.replace(c, "") A solution...
5
by: MLH | last post by:
I'm using A97 import data wizard to import text file N2 a table. The text file is a DIR listing produced by running dir jdc*.* /s c:\JDCs.txt The wizard is chopping the lines off at the...
6
by: simon.robin.jackson | last post by:
Ok. I need to develop a macro/vba code to do the following. There are at least 300 corrections and its expected for this to happen a lot more in the future. Therefore id like a nice...
13
by: Hongyu | last post by:
Hi, I have a datetime char string returned from ctime_r, and it is in the format like ""Wed Jun 30 21:49:08 1993\n\0", which has 26 chars including the last terminate char '\0', and i would...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.