|
Home > Archive > MS SQL Server > April 2005 > random selection
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hello,
I have a table of quotes. I would like to pull a new quote every 5 hours
for my web page (asp.net). I have a field "WebTextKey" that is an identity
key. My question is, how to go down the list and query the next quote? I
have no idea where to start, so any suggestions would be greatly
appreciated.
--
Thanks in advance,
sck10
| |
| Jens Süßmeyer 2005-04-29, 8:23 pm |
| Select TOP 1 * from sometable
Order by NewID()
If you want to store the displayed quote not too randomly a recent qoute you
can use this, if you want to begin the quotes every 7 days from start:
CREATE Table RecentDisplayedQuote
s
(
WebTextKey varchar(10),
DisplayTIme DATETIME
)
DELCARE WebTextKey varchar(10)
Select TOP 1 *,@WebTextKey = WebTextKey from sometable
NOT IN
(
Select WebTextKey From RecentDisplayedQuote
s And
Datediff(dd,7,Displa
yTIme) < 7
)
Order by NewID()
INSERT INTO RecentDisplayedQuote
s VALUES (WebTextKey,getdate(
))
HTH, Jens Suessmeyer.
---
http://www.sqlserver2005.de
---
"sck10" <sck10@online.nospam> schrieb im Newsbeitrag
news:uDkcjRQTFHA.2304@tk2msftngp13.phx.gbl...
> Hello,
>
> I have a table of quotes. I would like to pull a new quote every 5 hours
> for my web page (asp.net). I have a field "WebTextKey" that is an
> identity
> key. My question is, how to go down the list and query the next quote? I
> have no idea where to start, so any suggestions would be greatly
> appreciated.
>
> --
> Thanks in advance,
>
> sck10
>
>
|
|
|
|
|