Solved

update a table by comparing strings

Posted on 2016-09-07
2
49 Views
Last Modified: 2016-09-07
I had this question after viewing compare a value with a semicolon delimeted.

So based upon the above post this is what I would like to do

table 1 : userid
row 1      prs
row 2      ppp

table2
                   useridlist

row1         ccc;ddd;eee;PRS;rrr
row2         qqq;www;ttt


so i need a query that takes value for row 1 ('prs')  and compares it with useridlist of table 2 and since there is a match in row1 of table2 . since there is a match remove 'PRS' from table2 and update table two row with the following value :  ccc;ddd;eee;rrr

Thanks
0
Comment
Question by:PratikShah111
2 Comments
 
LVL 48

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 41788080
You can do it with a single command by using REPLACE function:
UPDATE table2
SET useridlist = REPLACE(table2.useridlist,table1.userid,'')
FROM table2
    INNER JOIN table1 ON table2.id=table1.id

Open in new window

NOTE: Run this first in a DEV environment before running it in Production.
0
 

Author Closing Comment

by:PratikShah111
ID: 41788211
Thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

856 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