Question : Delete from table based on full-row results of subquery

So I have a table, vDDDS, that has four columns. It has records that crop up that need to be found and deleted on a regular basis. Here is the query that will find the incorrect records:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
SELECT	'bEmployee', 1, Instance, SecurityGroup
FROM	vDDDS
WHERE	(Datatype = 'bEmployee') AND 
		(Qualifier = 1) AND 
		(SecurityGroup BETWEEN 1 AND 4) AND 
		Instance NOT IN (
			SELECT	CAST(Employee AS char) 
			FROM	PREH 
			WHERE	PRCo = 1 AND 
					PRGroup = vDDDS.SecurityGroup
		)


I want to write a procedure that will DELETE from vDDDS all records returned by the above query, but all four columns have to match (not just one). Is some kind of cursor loop required here?

Thanks!

Answer : Delete from table based on full-row results of subquery

delete v
from
vdds v
join (SELECT      'bEmployee' as datatype, 1 as b, Instance, SecurityGroup
FROM      vDDDS
WHERE      (Datatype = 'bEmployee') AND
            (Qualifier = 1) AND
            (SecurityGroup BETWEEN 1 AND 4) AND
            Instance NOT IN (
                  SELECT      CAST(Employee AS char)
                  FROM      PREH
                  WHERE      PRCo = 1 AND
                              PRGroup = vDDDS.SecurityGroup
            )
) x on v.columnname = x.columnname

not sure what your names are in your table
Random Solutions  
 
programming4us programming4us