Solved

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

Posted on 2016-09-26
2
40 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:
ScottPletcher 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

760 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

19 Experts available now in Live!

Get 1:1 Help Now