Solved

update a table by comparing strings

Posted on 2016-09-07
2
63 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 51

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

636 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