Y
yator
I am attempting to pull a random set of records using a Random Number and the
Top Value function. The Top Value changes depending on the specific group I
am looking at so I would like to obtain the Top Value from a table rather
than entering manually.
First, the appropriate statistically significant sample size is determined
for each group in my table by the query below. The sample size and group
information are added to [tbl_tt_sample_size].
INSERT INTO tbl_tt_sample_size ( MonthSample, Code, Fac, Sample )
SELECT
DateSerial(Year(Date()),Month(Date()),0) AS MonthSer,
tbl_tt_transfusions.Code,
tbl_tt_transfusions.Fac,
((0.5*(1-0.5))*Count([Unit#]))/((0.5*(1-0.5))+((0.1/1.96)*(0.1/1.96))*(Count([Unit#])-1)) AS Sample
FROM tbl_tt_transfusions
WHERE (((tbl_tt_transfusions.ISSUE_FLAG)="T") AND
((tbl_tt_transfusions.PtType) Not Like "O") AND ((tbl_tt_transfusions.UseDT)
Between DateSerial(Year(Date()),Month(Date())-1,1) And
DateSerial(Year(Date()),Month(Date()),1)))
GROUP BY DateSerial(Year(Date()),Month(Date()),0), tbl_tt_transfusions.Code,
tbl_tt_transfusions.Fac;
Sample data in [tbl_tt_sample_size]:
MonthSample CODE Fac Sample
9/30/2009 FFP C 34
9/30/2009 FFP H 75
9/30/2009 RC C 67
9/30/2009 RC H 87
10/31/2009 FFP C 35
10/31/2009 FFP H 65
10/31/2009 RC C 72
10/31/2009 RC H 88
(the [MonthSample] field is the last date of each month)
Next, a Random Number is added to field [tbl_tt_transfusions.].[RandomNo] by
the query below for later reference.
UPDATE tbl_tt_transfusions SET tbl_tt_transfusions.RandomNo =
CLng(Rnd([TransNo])*1000000)
WHERE (((tbl_tt_transfusions.RandomNo) Is Null));
Now I have a Random Number and Sample Size to work with. I can do this fine
with the query below, but I have to manually look up and change the Top Value
for each group each time.
SELECT TOP 87 tbl_tt_transfusions.RandomNo, tbl_tt_transfusions.Fac,
tbl_tt_transfusions.CODE, tbl_tt_transfusions.UseDT,
tbl_tt_transfusions.TransNo
FROM tbl_tt_transfusions
WHERE (((tbl_tt_transfusions.Fac)="H") AND ((tbl_tt_transfusions.CODE)="RC")
AND ((tbl_tt_transfusions.UseDT) Between #9/1/2009# And #10/1/2009#))
ORDER BY tbl_tt_transfusions.RandomNo;
Is there a way to "grab" [tbl_tt_sample_size].[Sample] to use as my Top
Value in the query above?
Top Value function. The Top Value changes depending on the specific group I
am looking at so I would like to obtain the Top Value from a table rather
than entering manually.
First, the appropriate statistically significant sample size is determined
for each group in my table by the query below. The sample size and group
information are added to [tbl_tt_sample_size].
INSERT INTO tbl_tt_sample_size ( MonthSample, Code, Fac, Sample )
SELECT
DateSerial(Year(Date()),Month(Date()),0) AS MonthSer,
tbl_tt_transfusions.Code,
tbl_tt_transfusions.Fac,
((0.5*(1-0.5))*Count([Unit#]))/((0.5*(1-0.5))+((0.1/1.96)*(0.1/1.96))*(Count([Unit#])-1)) AS Sample
FROM tbl_tt_transfusions
WHERE (((tbl_tt_transfusions.ISSUE_FLAG)="T") AND
((tbl_tt_transfusions.PtType) Not Like "O") AND ((tbl_tt_transfusions.UseDT)
Between DateSerial(Year(Date()),Month(Date())-1,1) And
DateSerial(Year(Date()),Month(Date()),1)))
GROUP BY DateSerial(Year(Date()),Month(Date()),0), tbl_tt_transfusions.Code,
tbl_tt_transfusions.Fac;
Sample data in [tbl_tt_sample_size]:
MonthSample CODE Fac Sample
9/30/2009 FFP C 34
9/30/2009 FFP H 75
9/30/2009 RC C 67
9/30/2009 RC H 87
10/31/2009 FFP C 35
10/31/2009 FFP H 65
10/31/2009 RC C 72
10/31/2009 RC H 88
(the [MonthSample] field is the last date of each month)
Next, a Random Number is added to field [tbl_tt_transfusions.].[RandomNo] by
the query below for later reference.
UPDATE tbl_tt_transfusions SET tbl_tt_transfusions.RandomNo =
CLng(Rnd([TransNo])*1000000)
WHERE (((tbl_tt_transfusions.RandomNo) Is Null));
Now I have a Random Number and Sample Size to work with. I can do this fine
with the query below, but I have to manually look up and change the Top Value
for each group each time.
SELECT TOP 87 tbl_tt_transfusions.RandomNo, tbl_tt_transfusions.Fac,
tbl_tt_transfusions.CODE, tbl_tt_transfusions.UseDT,
tbl_tt_transfusions.TransNo
FROM tbl_tt_transfusions
WHERE (((tbl_tt_transfusions.Fac)="H") AND ((tbl_tt_transfusions.CODE)="RC")
AND ((tbl_tt_transfusions.UseDT) Between #9/1/2009# And #10/1/2009#))
ORDER BY tbl_tt_transfusions.RandomNo;
Is there a way to "grab" [tbl_tt_sample_size].[Sample] to use as my Top
Value in the query above?