Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This will give you the ID's from @T that already have the combination of values provided in @NewValues.</p> <pre><code>declare @T table (ID int, Value char(1)) insert into @T values (1, 'A'),(2, 'B'),(3, 'C'),(3, 'C'), (4, 'A'),(4, 'D'),(5, 'A'),(5, 'C'), (5, 'D') declare @NewValues table(ID int, Value char(1)) insert into @NewValues values (6, 'A'), (6, 'D') select T.ID from @T as T inner join @NewValues as N on T.Value = N.Value group by T.ID having count(*) = (select count(*) from @NewValues) </code></pre> <p>Result:</p> <pre><code>ID 4 5 </code></pre> <p>If you only want exact matches, meaning that ID=5 would not be returned because it also have one row with Value='C' you can use this instead.</p> <pre><code>select T.ID from @T as T left outer join @NewValues as N on T.Value = N.Value group by T.ID having count(N.Value) = (select count(*) from @NewValues) and count(*) = (select count(*) from @NewValues) </code></pre> <p>I see that you have (3,'C') and (3,'C') in your table. If you want to detect that with the input (6, 'C') and (6, 'C') you need this query.</p> <pre><code>select T.ID from @T as T left outer join (select distinct Value from @NewValues) as N on T.Value = N.Value group by T.ID having count(N.Value) = (select count(*) from @NewValues) and count(*) = (select count(*) from @NewValues) </code></pre> <p>Fill `@NewValues? table with a string split function.</p> <pre><code>-- Paramenter to SP declare @ParamID int = 6 declare @ParamValues varchar(100) = 'A,D' declare @NewValues table(ID int, Value char(1)) insert into @NewValues select @ParamID, s from dbo.Split(',', @ParamValues) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload