Advertisement

03.21.2006 at 01:04PM PST, ID: 21783095
[x]
Attachment Details

Use RAND to return result set in different order

Asked by JeffDrummond in MS SQL Server

Tags: rand, order, use, result

I'm trying to use RAND to return my result set in a different order each time it is executed.
Am I off base on this on this approach?  

This is my query, which returns the same data in the same order every time it runs.

-----------------------
alter      PROCEDURE DBO.hh_Event_GetFeatured
@OrganizationId int
AS

-------------------------------------------------------------------------------------
/* Step 1  Get all approved featured events for the organization specified.        */
-------------------------------------------------------------------------------------

SELECT      T1.*,
      T2.*
FROM      HOMEHOSTING_FEATUREDEVENTS T1
      JOIN HOMEHOSTING_EVENTS T2 ON T1.EVENTID = T2.ID
            
WHERE      T1.ISAPPROVED = 1
AND      T2.[Date] > GetDate()
AND      T2.ORGANIZATIONID = @OrganizationId

ORDER BY RAND()Start Free Trial
 
Loading Advertisement...
 
[+][-]03.21.2006 at 01:24PM PST, ID: 16251812

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: rand, order, use, result
Sign Up Now!
Solution Provided By: acampoma
Participating Experts: 1
Solution Grade: A
 
 
[+][-]03.21.2006 at 01:28PM PST, ID: 16251848

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32