Solved

compare a value with a semicolon delimeted

Posted on 2016-09-01
4
45 Views
Last Modified: 2016-09-06
I am trying to write query where I am trying to compare a value from one table with a value from second table where the value in the second table is in a row with some other values which is semicolon delimeted

example

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 do not show it. then it takes row1 of table 1 and compares with useridlist of table2 and since there no match it shows.
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
4 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 500 total points
ID: 41780714
check this.
select *
  from table1 t1
  left join table2 t2 on patindex('%'+t1.userid+'%',t2.useridlist) > 0
 where t2.useridlist is null

Open in new window

0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41781022
Use any of the below approaches

Solution 1

---------------------------------------

SELECT Words.Texts Word , r.Texts Texts
FROM Words
CROSS APPLY
(
    SELECT Texts FROM Texts
)r
WHERE CHARINDEX(Words.Texts,r.Texts,0) > 0

SOLUTION 2

-------------------------------------

SELECT Words.Texts Word , r.Texts Texts
FROM Words
CROSS JOIN Texts r
WHERE CHARINDEX(Words.Texts,r.Texts,0) > 0


URL for ref --
https://msbiskills.com/2016/07/06/sql-puzzle-word-search-puzzle/


Enjoy ! Let me know in case you want me to write the exact query.. for that you need to share your table design for both the tables.
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41784593
@Author - Do you need more help with this ?
0
 

Author Closing Comment

by:PratikShah111
ID: 41786766
thank you Sharath for your help. exactly what I wanted.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

761 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