Solved

update a table by comparing strings

Posted on 2016-09-07
2
42 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 47

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.

803 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