-
Replacing a string.
I have a field in a sql7 db. The data in the field may look like this:
1007;1000;10013
I need to remove some data from the field but not all of it. I need to remove
1000; and replace it with null. Any idea?
-
Re: Replacing a string.
"Dennis" <dtucker01@hotmail.com> wrote:
>
>I have a field in a sql7 db. The data in the field may look like this:
>1007;1000;10013
>
>I need to remove some data from the field but not all of it. I need to remove
>1000; and replace it with null. Any idea?
Hi,
Update TableName Set FieldName = REPLACE(FieldName, '1000;', '')
Where FieldName Like '%1000;%'
All occurences of '1000;' will be replace with a nullstring which means removed
from the string.
Look up the REPLACE-function in BOL.
Bernie
-
Re: Replacing a string.
Write a quick little VB app that selects the PK from the table and the field
your needing to modify where the field needing to modify contains the 1000;
Using the VB app, go through each record do a replace(fxn) on the record
field and then peform the update.
so something like...
dim con as connection
dim rs as recordset
DIm SQL as string
set con = getgonnection() 'Get connection is fxn that establishes connection
to db
SQL = "SELECT PK, Field from tblName where Instr(Field,'1000;')>0"
rs.open (SQL,CON)
While not rs.eof
SQL = "Update tblName set Field = '" & Replace(rs.fields("Field"),"1000;","NULL;")
& "' WHERE PK=" & rs.fields("PK")
conn.execute(SQL)
wend
"Dennis" <dtucker01@hotmail.com> wrote:
>
>I have a field in a sql7 db. The data in the field may look like this:
>1007;1000;10013
>
>I need to remove some data from the field but not all of it. I need to remove
>1000; and replace it with null. Any idea?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks