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)
 Parsing asp variable.

Author  Topic 

TazMania
Yak Posting Veteran

63 Posts

Posted - 2004-11-01 : 02:36:14
Hi :)

Does anyone of you guru's :) know how to parse a variable from a stored procedure, this stored procedure creates a temp table which resides all the values i need ?

What i need to do is parsing the value from a form text field, to the below sproc, in the select statement. ( WHERE Mobilnummer LIKE '%" & Rsearch & "%' )

I've used the example, from 4 guys from rolla. with a small modification.


CREATE PROCEDURE sp_PagedItems
(
@Page int,
@RecsPerPage int
)
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 varchar(50),
Mobilnummer varchar(50),
Opkaldstype varchar(255),
Opkaldsmodtager varchar(255),
Samtalestart datetime,
Samtalevarighed varchar(50),
Samtalepris varchar(50),
)


-- Insert the rows from tblItems into the temp. table
--
--
INSERT INTO #TempItems (Kontraktnummer,Mobilnummer,Opkaldstype,Samtalestart,Samtalevarighed,Samtalepris)
SELECT KontraktNummer,MobilNummer,Opkaldstype,Samtalestart,Samtalevarighed,Samtalepris FROM Usage WHERE Mobilnummer LIKE '%" & Rsearch & "%' 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


Any help will be much appreciated !

Best regards
Taz

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-11-01 : 07:14:15
give us some sample data and what the result should look like after it is run through the procedure... you will get the best answers this way!

Corey
Go to Top of Page

TazMania
Yak Posting Veteran

63 Posts

Posted - 2004-11-01 : 08:18:20
Hi again,

thx for the reply.

Oki here goes.


<%
Set objRS = Server.CreateObject("ADODB.Recordset")

'How many records per page do we want to show?
Const iRecordsPerPage = 10

Dim currentPage 'what page are we on??
Dim bolLastPage 'are we on the last page?

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

Rsearch = "12345678"

'Show the paged results
strSQL = "sp_PagedItems " & currentPage & "," & iRecordsPerPage
objRS.Open strSQL, Conn

'See if we're on the last page
if Not objRS.EOF then
if CInt(objRS("MoreRecords")) > 0 then
bolLastPage = False
else
bolLastPage = True
end if
end if
%>


Result:

<%
Do While Not objRS.EOF %>
<TR><TD ALIGN=LEFT BGCOLOR=GRAY>
<%=objRS("Mobilnummer")%>
</TD><TD ALIGN=CENTER BGCOLOR=GRAY>
<%=objRS("Kontraktnummer")%>
</TD></TR>
<% objRS.MoveNext
Loop %>


Best regards
Taz
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-11-01 : 08:45:25
So are you just trying to add a 'search' parameter to your stored procedure?

if so you will call it as:

...
Rsearch = "12345678"

'Show the paged results
strSQL = "sp_PagedItems " & currentPage & "," & iRecordsPerPage & ", '" & Rsearch & '"
objRS.Open strSQL, Conn
...


and in your stored procedure :


Create Procedure dbo.sp_PagedItems
currentPage int,
recordsPerPage int,
searchStr varchar(100)
As
...

Where someCol like '%'+@searchStr+'%'


Of course, maybe I am just being thick and still don't understand the question...

Corey
Go to Top of Page

TazMania
Yak Posting Veteran

63 Posts

Posted - 2004-11-01 : 08:59:06
Hi again :)

Thank you so much for the help !!

Just what i needed.

Best regards
Taz
Go to Top of Page
   

- Advertisement -