Avatar of hojohappy
hojohappy
 asked on

Help with SQL Command to compare the contents of two table fields

I need help with SQL command.  I have two SQL server tables with I need to validate the contents of one table field against another.  The table [VG-Attributes].LOVs contains a partial set of values but I need to validate these values against the complete set which is in [VG-LOVs].[Combined Field Type Values].

[VG-Attributes].LOVs = No
[VG-LOVs].[Combined Field Type Values]  = Yes;No

I need to report any value from [VG-Attributes].LOVs that is not in [VG-LOVs].[Combined Field Type Values].  For example;

[VG-Attributes].LOVs = XX
[VG-LOVs].[Combined Field Type Values]  = Yes;No


SELECT     [VG-Attributes].LOVs, [VG-LOVs].[Combined Field Type Values]
FROM         [VG-Attributes] INNER JOIN
                      [VG-LOVs] ON [VG-Attributes].LOV_ID = [VG-LOVs].[LOV ID ]
                   where [VG-Attributes].LOVs does not contain all values from [VG-LOVs].[Combined Field Type Values]
Microsoft SQL Server 2008

Avatar of undefined
Last Comment
lcohan

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Sharath S

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
lcohan

I would use PATINDEX SQL Function to check existence of one string in the other:


patindex:  http://msdn.microsoft.com/en-us/library/ms188395(SQL.105).aspx

--this will show all that NOT exists and if you want the match just change  = 0 to > 0 in query below

SELECT     [VG-Attributes].LOVs, [VG-LOVs].[Combined Field Type Values]
FROM         [VG-Attributes] INNER JOIN
                      [VG-LOVs] ON [VG-Attributes].LOV_ID = [VG-LOVs].[LOV ID ]
where patindex([VG-Attributes].LOVs,[Combined Field Type Values])=0
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23