Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-09-26
2
Medium Priority
?
75 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

722 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