Solved

How to update "part of a text field" without changing the entire contents?

Posted on 2016-09-26
2
54 Views
Last Modified: 2016-09-26
Experts,

I have a table 'Table1' that has a Text Field that contains data like this:

RowID,DetailData
1,1P0014.241102.0000                          1053591503          5806909             1230                                  HP23

The 3rd set of numbers in my DetailData text column is my MemberID field which is '5806909' in the above example. I need to know how to update this MemberID WITHOUT changing the contents of the rest of the Text. For example, the NewMemberId is '6006100'.  

I need the change to be reflected like this:

RowID,DetailData
1,1P0014.241102.0000                          1053591503          6006100             1230                                  HP23

The "spacing" and character set cannot be changed at all.. but only the 3rd set of numbers which again is my MemberID.

How can I accomplish this within an UPDATE Script?

Thanks
0
Comment
Question by:MIKE
2 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 41816970
If you have a specific byte location, use STUFF:

SELECT ..., STUFF(DetailData, CHARINDEX('5806909', DetailData), LEN('5806909'), '6006100'), ...
FROM table_name

Or:
UPDATE table_name
SET DetailData = STUFF(DetailData, CHARINDEX('5806909', DetailData), LEN('5806909'), '6006100')
WHERE ...
0
 
LVL 17

Author Closing Comment

by:MIKE
ID: 41816982
Thanks you!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

777 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