Solved

update a table by comparing strings

Posted on 2016-09-07
2
28 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 45

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now