Multiple variables



Hi

Our database has a series of tables that are all linked by a field called
company_code (amongst others). Occasionally data needs to be deleted and
this involves deleting multiple rows from some of these tables and updating
data in another table. I tend to wait until there are a few to do and then
do them all at once. To make the task less onerous I have saved a simple
script that does all the deletions for each code at once, a cut down version
is below:

/*Delete all pay data and make contact only*/
DECLARE @code int

SET @code = 12345

DELETE company_size
WHERE company_code = @code

--Other deletions go in here

UPDATE company_basic
SET report_status = null,
report_entry_urn = null,
next_rpt_archive = null,
/* Other fields to be updated... */
WHERE company_code = @code

What I would like to be able to do is change the 'where' statements so that
they use the IN operator rather than the = operator. Is there a way to do
this using variables so I can assign a list of company codes to a variable
that can be used with an IN operator?

Thanks
Andy


.