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 December 17th, 2004, 03:03 AM
prit_vicky prit_vicky is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Gujarat India
Posts: 30 prit_vicky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 24 m 41 sec
Reputation Power: 4
Send a message via Yahoo to prit_vicky
Getting random record from table.

Hi,
Can anybody help me?

I have a one table with two field
id---number (primary)
Quotes- text

it contaning 50 records. I want to get single record but
in random order.

every time it will give different record?

plz, help me..
pritesh

Reply With Quote
  #2  
Old December 17th, 2004, 04:30 PM
mwalts's Avatar
mwalts mwalts is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Victoria, BC Canada
Posts: 482 mwalts User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 30 sec
Reputation Power: 5
Do you mean to do this directly in an SQL statement? Cause I dont' see that happening. There should be a way to do it in a stored procedure using cursors... you'll probably need a second table (a copy of the first) which you would then remove entries from so that you didn't get repeats... to tell you the truth I'd do this sort of thing in a programming language that talks to the database through ODBC or somthing

-mwalts

Reply With Quote
  #3  
Old December 18th, 2004, 12:41 PM
A2k's Avatar
A2k A2k is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 166 A2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 44 m 10 sec
Reputation Power: 4
if your using Microsoft SQL Server check out the rand() keyword. If you're familia with C++/C it works the same way use the datepart() and getdate() to create a seed.

HTH

Reply With Quote
  #4  
Old December 20th, 2004, 12:08 AM
satishkumarj satishkumarj is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 109 satishkumarj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 37 m
Reputation Power: 4
Thumbs up order by newid()

Hi,

If ur using SQLServer then use order by newid() function to
get random rows

Code:
  
 
select * from your_table where your_condtion order by newid()
 


i hope it will helps u....

Cheers,
Satish Kumar J.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Getting random record from table.


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 1 hosted by Hostway