|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Different rand result for each row
Here is the statement:
Code:
SELECT
Q.ID AS QID,
Q.Batch AS Q_B,
B.[order] AS B_O,
B.comments AS B_C,
ET.Description AS ETD,
ET.ID AS ETI,
Br.Brand AS BRB,
Br.ID AS BRI,
Q.ReceiveDate AS QRD,
CAST(FLOOR(REVERSE(RAND(B.[order]))) AS INT) AS RS_ID
INTO
#TMP
FROM
QA Q
LEFT JOIN
Batch B
ON B.QAID=Q.ID
LEFT JOIN
QAErrors QE
ON QE.ID=B.QEID
LEFT JOIN
ErrorTypes ET
ON ET.ID=QE.ErrorTypeID
LEFT JOIN
Brands Br
ON Br.ID=Q.BrandID
WHERE
KeyDate
BETWEEN
@mindate
AND
@maxdate;
The random seed works great. BUT if there are more than 1 same order, (the only reason why there are more than 1 order is because there *IS* an error) there are duplicated random seed like so: 108218 474492602 246271011 NAME KEYED IN ERROR Error in Name 2 Virginia 7 2005-08-01 10:44:00 3474 108218 474492602 246271011 ADDRESS KEYED IN ERROR Error in Address 3 Virginia 7 2005-08-01 10:44:00 3474 The random on end are '3474' So I was thinking of this: Code:
IF ET.ID is not null
BEGIN
CAST(FLOOR(REVERSE(RAND(B.[order]+CAST(ET.ID AS REAL)))) AS INT) AS RS_ID
END
ELSE
BEGIN
CAST(FLOOR(REVERSE(RAND(B.[order]))) AS INT) AS RS_ID
END
But was unable to get it to work.... -- I tried to read online help, googled for it to no avail... How do I get around to it? |
|
#2
|
|||
|
|||
|
I have a question. Why do you need to select a random # there. Can you live with a sequential number instead? If so, make that last field in the temp table an IDENTITY field.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. |
|
#3
|
|||
|
|||
|
Quote:
Because I am trying to do a random select of 70% out of orders reviewed and assign operators to inspect. The operators are doing "do top 15 orders, then after that rush 'em!" psychology to beat the reviewer's detection. So I decided to use random seed, then order them and hit 'em where they hurt the most. |
|
#4
|
|||
|
|||
|
I got it.
Code:
SELECT * FROM WHEREVER ORDER BY NewID(); OR Code:
SELECT NewID(), * FROM WHEREVER; |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Different rand result for each row |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|