?
Solved

update a table by comparing strings

Posted on 2016-09-07
2
Medium Priority
?
69 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
[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 52

Accepted Solution

by:
Vitor Montalvão earned 2000 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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 combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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.

719 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