Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 4th, 2005, 01:34 PM
LinuxGold LinuxGold is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 45 LinuxGold User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 4 sec
Reputation Power: 4
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?

Reply With Quote
  #2  
Old August 4th, 2005, 05:02 PM
Scorpions4ever Scorpions4ever is offline
Mad Rater
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 126 Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 31 m 44 sec
Reputation Power: 8
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.

Reply With Quote
  #3  
Old August 5th, 2005, 12:54 AM
LinuxGold LinuxGold is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 45 LinuxGold User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 4 sec
Reputation Power: 4
Quote:
Originally Posted by Scorpions4ever
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.


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.

Reply With Quote
  #4  
Old August 5th, 2005, 10:55 AM
LinuxGold LinuxGold is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 45 LinuxGold User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 18 m 4 sec
Reputation Power: 4
I got it.

Code:
SELECT
*
FROM
WHEREVER
ORDER BY
NewID();


OR

Code:
SELECT
NewID(),
*
FROM
WHEREVER;

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Different rand result for each row


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT