I have a SQL statement that displays the following values, but the number of rows can be anything.
SELECT NameID,Name,ValueID,Value FROM Options WHERE OptionID = 10000
Which results to:
NameID | Name | ValueID | Value
100 | Color | 10000 | Black
101 | Size | 10005 | Large
Or sometimes even:
NameID | Name | ValueID | Value
100 | Color | 10000 | Black
101 | Size | 10005 | Large
102 | Height | 10009 | Tall
103 | Width | 10006 | Wide
I’m trying to write a Stored Procedure that can allow me to check if ALL of these value’s exist based on OptionID
Therefore,
- The statement would allow an input of
OptionIDof course to only show all the options inside theOptionstable for thisOptionID - The statement would allow an input of multiple paired values for
NameIDandValueID
The general logic needed would be something like this:
if ALL NameID and ValueID Pairs with-in an OptionID Exists
(as shown above in the results)
Then Return 'Unique Combination'
Else Return 'Combination Exists'
Boolean would be fine as well. I’ve tried using a PIVOT to see if it can be done like this, but that was a bit more than i think i needed, but maybe not.. Any suggestions?
You can use an if exists statement.
Updated answer