Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Need a little help with some sproc code.

Author  Topic 

TazMania
Yak Posting Veteran

63 Posts

Posted - 2004-12-15 : 04:36:09
Hi,

I've modified a paging example from 4guysfromrolla made by Daniel Anderson, first with a search string which works perfectly.. but i've now added a new variable which consist of the current month.

Sproc code:

CREATE PROCEDURE sp_PagedItemsUsage
(
@Page int,
@RecsPerPage int,
@searchStr varchar(100),
@searchDate varchar(3)
)
AS

-- http://www.4guysfromrolla.com/webtech/062899-1.shtml
-- We don't want to return the # of rows inserted
-- into our temporary table, so turn NOCOUNT ON
SET NOCOUNT ON

--Create a temporary table
CREATE TABLE #TempItems
(
ID int IDENTITY,
Kontraktnummer nvarchar(50),
Mobilnummer nvarchar(50),
Opkaldstype nvarchar(255),
Opkaldsmodtager nvarchar(255),
Samtalestart datetime,
Samtalevarighed datetime,
Samtalepris nvarchar(50),
)

-- Insert the rows from tblItems into the temp. table CONVERT(char(20), ytd_sales) LIKE '3%'
INSERT INTO #TempItems (Kontraktnummer,Mobilnummer,Opkaldstype,Opkaldsmodtager,Samtalestart,Samtalevarighed,Samtalepris)
SELECT KontraktNummer,MobilNummer,Opkaldstype,Opkaldsmodtager,Samtalestart,Samtalevarighed,Samtalepris FROM Usage WHERE Month(SamtaleStart) LIKE '%'+@searchDate+'%' AND Mobilnummer LIKE '%'+@searchStr+'%' ORDER BY Samtalestart DESC

-- Find out the first and last record we want
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)

-- Now, return the set of paged records, plus, an indiciation of we
-- have more records or not!
SELECT *,
MoreRecords =
(
SELECT COUNT(*)
FROM #TempItems TI
WHERE TI.ID >= @LastRec
)
FROM #TempItems
WHERE ID > @FirstRec AND ID < @LastRec

-- Turn NOCOUNT back OFF
SET NOCOUNT OFF
GO


my asp code :

Const iRecordsPerPage = 30

Dim currentPage ' Hvilken side er vi på ?
Dim bolLastPage ' Er vi på sidste side ?

if len(Request.QueryString("page")) = 0 then
currentPage = 1
else
currentPage = CInt(Request.QueryString("page"))
end if

' Viser det sideinddelt resultat, samt henter sproc kode fra sql serveren.
strSQL = "sp_PagedItemsUsage " & currentPage & "," & iRecordsPerPage & "," & ValgMaaned & "," & Rsearch

objRS.Open strSQL, Conn


Rsearch = "28990116"
ValgMaaned = "9"

But somehow my page will not show any data.. i've tried to convert the @Datesearch to int but then I get a error which states that I can't convert @Datesearch char to int.

Any advice or help would be much appreciated.

Best regards
Taz

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-12-15 : 07:35:42
what's wrong with:
Month(SamtaleStart) = @searchDate

Go with the flow & have fun! Else fight the flow
Go to Top of Page

TazMania
Yak Posting Veteran

63 Posts

Posted - 2004-12-15 : 07:42:13
Hi spirit1,

thx for the reply,

I've tried that and I still get no result back..
But if I set month(samtalestart) = '9' it woarks.. strange



Best regards
Taz
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-12-15 : 07:57:34
change @searchDate to int.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

TazMania
Yak Posting Veteran

63 Posts

Posted - 2004-12-15 : 07:58:45
wuhu.. got it working :)

for some reason the sproc code didn't see @searchDate variable properly.. the correct code should be :

strSQL = "sp_PagedItemsUsage " & currentPage & "," & iRecordsPerPage & "," & Rsearch & "," & ValgMaaned


Best regards
Taz
Go to Top of Page
   

- Advertisement -