Jag har följande sp för att returnera ett slumpmässigt recordset.
Alter PROCEDURE getRandomAd
AS
declare @nRecordCount int
declare @nRandNum int
-- Create a temporary table with the same structure of
-- the table we want to select a random record from
CREATE TABLE #TempTable
(
strImageSrc varchar(255),
intId int identity(1,1)
)
-- Dump the contents of the table to search into the temp. table
INSERT INTO #TempTable
Select strImageSrc From tblAd_ad Where intId_adc = 1 And bitActive = 1
-- Get the number of records in our temp table
Select @nRecordCount = count(*) From #TempTable
-- Select a random number between 1 and the number
-- of records in our table
Select @nRandNum = Round(((@nRecordCount - 2) * Rand() + 1), 0)
-- Select the record from the temp table with the
-- ID equal to the random number selected...
Select strImageSrc From #TempTable
Where intId = @nRandNum
Koden är från http://www.4guysfromrolla.com/webtech/081100-1.shtml.
Jag anropar den på asp-sidan med
Set objConn = Server.CreateObject("ADOdb.Connection")
Set objRS = Server.CreateObject("ADOdb.Recordset")
With objConn
.Open strConn
.Execute("getRandomAd")
.Close
End With
intId = objRS(0)
strImageSrc = objRS(1)
objRS.Close
Set objRS = Nothing
Set objConn = Nothing
Jag får då felmeddelandet
Item cannot be found in the collection corresponding to the requested name or ordinal.
.
Kör jag den i InterDev står det bara
3 rows affected by last query
och inget recordset returneras.
Vad är fel? Är det överhuvudtaget ett bra sätt att hämta ett slumpmässigt valt recordset?