in reply to Dealing with random subsets

Win:

OK, here's a quick way to do it in Perl ... feel free to edit it into shape:

#/usr/bin/perl -w use strict; use warnings; use DBI: my $DBH=DBI->connect("dbi:ODBC:driver={SQL Server};" ."SERVER=XXXX; DATABASE=YYYY;","UID","PWD") or die $DBI::errstr; $DBH->do(qq| DECLARE @Number_of_government_regions INT SET @Number_of_government_regions = (SELECT 354) if exists(select 1 from INFORMATION_SCHEMA.tables where table_name = ' +MyNumbers') DROP TABLE MyNumbers; --MyNumbers --===== Create and populate the Tally table on the fly SELECT TOP 1000 IDENTITY(INT,1,1) AS Nums INTO dbo.MyNumbers FROM Master.dbo.SysColumns sc1, Master.dbo.SysColumns sc2 --===== Add a Primary Key to maximize performance ALTER TABLE dbo.MyNumbers ADD CONSTRAINT PK_MyNumbers_N PRIMARY KEY CLUSTERED (Nums) WITH FILLFACTOR = 100 INSERT INTO Random_region_lookup_table_TEMP (Generation_number, Place +_key) SELECT n.Nums, r.Number_count FROM MyNumbers n CROSS JOIN Region_lookup r WHERE n.Nums <= @Number_of_repeats ORDER BY n.Nums, NEWID() UPDATE Random_region_lookup_table_TEMP SET Place_key = (Place_key)%354 + 1 INSERT INTO Random_region_lookup_table_TEMP (Generation_number, Place_ +key) SELECT n.Nums, r.Number_count FROM MyNumbers n CROSS JOIN Region_lookup r ORDER BY n.Nums, NEWID() |) or die $DBI::errstr;
Heh ... hope this helps!

</snarky_mode>

...roboticus