Solved

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

Posted on 2016-09-26
2
67 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 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Format Date fields 11 64
Removing SCCM 2016 4 53
EF5 How do I stop pre-compiled views? 8 54
Need more granular date groupings 4 45
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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…
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

738 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