Could someone please offer me an alternative Perl solution to the following T-SQL code. I ask because the attempted solution below does not quite work as expected. I am trying to fill the Random_region_lookup_table_TEMP table. This table offers random subsets of geographic regions (to a fixed number) and this is repeated x number of times. The value of max(x) is the total number of generations. Each generation has the same number of regions. Each region subset is pulled from the same total set. No region is represented more than once in a single generation. Regions can be represented in multiple generations.
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()
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.