Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 3rd, 2009, 05:59 AM
Authorized User
 
Join Date: Nov 2007
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default To display the banners in sequential manner

I want to display the banners in a sequential manner instead of displaying it randomly.Say for eg if there are 3 records then it should display 1st then 2nd and then 3rd. Following is the stored procedure which displays the banner randomly.But I want it in sequential manner.

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[sp_RandomBanner]
as
Declare @rows int
Declare @nRandNum int
create table #TempTable
(
dtPostDate datetime,
vchrLinkURL varchar(100),
vchrImagePath varchar(100),
vchrImageName varchar(50),
vchrStatus varchar(50),
vchrChangeStatus varchar(50),
intBannerID int identity(1,1)
)
INSERT INTO #TempTable
Select dtPostDate, vchrLinkURL, vchrImagePath,vchrImageName,vchrStatus,vchrChangeS tatus From tblBanner where vchrStatus='Running'
select @rows=count(*) from #TempTable
select @nRandNum=Round(((@rows - 1) * Rand() + 1), 0)
select * from #TempTable where intBannerID=@nRandNum and vchrStatus='Running'

Regards,
Jijish
 
Old January 3rd, 2009, 09:05 AM
jminatel's Avatar
Wrox Staff
Points: 18,059, Level: 58
Points: 18,059, Level: 58 Points: 18,059, Level: 58 Points: 18,059, Level: 58
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Posts: 1,906
Thanks: 62
Thanked 139 Times in 101 Posts
Default

Please don't cross post:
To display the banners in sequential manner
__________________
Jim Minatel
Associate Publisher, WROX - A Wiley Brand
Did someone here help you? Click on their post!
 
Old January 4th, 2009, 03:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hello. You want to display the banners sequential for the same user of for diferents users?? why just not add a table that takes the count??
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old January 4th, 2009, 05:42 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I don't understand the point of creating the temp table, AT ALL.

You don't say how you are *using* this SQL, but if it is part of ANY kind of conventional web site/web page (ASP, ASP.NET, PHP, JSP), that temp table will be WIPED OUT each and every time the web page is sent to the browser, because ALL these technologies only keep the connection open so long as the page is being rendered and then close it once the HTML is sent to the browser. And closing the connect DELETES the temp table!

Tell us what technology you are using for your web page: ASP, ASP.NET, PHP, JSP, CF, or what???

Incidentally, your code for picking one random banner is HORRIBLY over-complicated for SQL Server.

You could accomplish the same thing with no need of the useless temp table:
Code:
CREATE procedure [dbo].[sp_RandomBanner]
AS
Select TOP 1 dtPostDate, vchrLinkURL, vchrImagePath, vchrImageName, 
                  vchrStatus,vchrChangeStatus 
FROM tblBanner 
WHERE vchrStatus='Running'
ORDER BY NEWID( )
Anyway, as GBianchi asked, do you want the banners to be sequential *PER USER* or sequential for *ALL* users???

And a *VERY* important question, that could make all this a lot simpler and a lot faster: How many banners are there??? [If there are only a few--say less than 100?--you could just put them into memory and forget using the DB and get much better efficiency. Especially easy to do with ASP and ASP.NET, which I'm guessing is what this is for, since you are using SQL Server.]





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 8: User Controls - Shows all banners VeganMan BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 April 9th, 2008 03:45 PM
Sequential Numbers ricespn Access 5 February 17th, 2007 02:54 AM
Sequential Numbers ricespn SQL Server 2000 14 November 1st, 2006 12:08 PM
HELP!!!!! Sequential DTS e_cabrera_g SQL Server DTS 1 October 11th, 2006 11:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.