|
Blastrix
Posting Yak Master
208 Posts |
Posted - 2001-05-23 : 15:32:42
|
| I have the following SP:CREATE PROCEDURE spHotLaps_takeLap ( @trackId int, @page int, @perPage int )ASSET NOCOUNT ONCREATE TABLE #tempHL ( tempId int IDENTITY, hotLapId int, trackId int, lapDateTime dateTime, username varchar(30), rating int, comment text )INSERT INTO #tempHL (hotLapId, trackId, lapDateTime, username, rating, comment) SELECT hotLapId, trackId, lapDateTime, username, rating, comment FROM hotLaps, users WHERE trackId = @trackId AND hotLaps.userId = users.userId ORDER BY rating DESCDECLARE @firstRec int, @lastRec intSELECT @firstRec = (@page - 1) * @perPageSELECT @lastRec = (@page * @perPage + 1)SELECT trackName, trackCity, trackState, trackCountry, trackLength, trackStatus, trackWebsite, trackNumTurns, trackImage, ( SELECT COUNT(*) FROM #tempHL HL WHERE HL.tempId >= @lastRec ) AS nextPage, ( SELECT COUNT(*) FROM #tempHL ) AS totalComments, HL.*FROM #tempHL HL RIGHT JOIN tracks ON HL.trackId = tracks.trackIdWHERE tracks.trackId = @trackId AND HL.tempId > @firstRec AND HL.tempId < @lastRecGONow, no matter what, I need all the of the info requested from the table 'tracks'. The join works fine if there is at least one record in the temp table. However, if there are no records, then it doesn't return anything. If I drop the 'AND HL.tempId > @firstRec AND HL.tempId < @lastRec' then it will return everything fine. However, those conditions are needed so that it gets the appropriate records. |
|