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)
 Two resultsets from one stored proc

Author  Topic 

Pumpkins_Man
Starting Member

20 Posts

Posted - 2002-07-11 : 19:10:59
Hey guys,
I'm in need of some serious help. I've been working on an intranet and i've been doing the frontend stuff (asp and html) and another guy has been working on the backend in sql server. so anyways, he's been on sql training for this week and remotely working on the database from home. he's been doing some funky new things that have completely confused me.

he's written this procedure:
 create procedure User_Details
@accountName varchar(50),
@code bit Output
As
declare @result table ([User_ID] int,
Dept_ID int,
Status_ID int,
Availability char(25))
declare @count int

insert into @result ([User_ID], Dept_ID, Status_ID, Availability)
select u.[User_ID], u.Dept_ID, s.Status_ID, t.[Name] as 'Availability'
from Users u inner join Staff_Tracking s on u.[User_ID] = s.[User_ID]
inner join Tracking_Status t on s.Status_ID = t.Status_ID
where Account_Name = @accountName
and s.Status_Time = (select max(s2.Status_Time) from Staff_Tracking s2 where s2.[User_ID] = u.[User_ID])

select @count = count(*) from @result

if @count > 0
begin
set @code = 1
select * from @result
end else
set @code = 0


GO

it returns two resultsets and i don't know how to put the data into a recordset in asp. i would've thought that this would've done the job:

 dim dataConn, exist, username, cmd
set dataConn = server.createobject("ADODB.Connection")
set cmd = server.createobject("ADODB.Command")
set rsUser = server.createobject("ADODB.Recordset")
dataConn.Open "DSN=intranet;uid=intranet;pwd=bronty"
username = Right(Request.ServerVariables("LOGON_USER"), Len(Request.ServerVariables("LOGON_USER")) - InStr(Request.ServerVariables("LOGON_USER"),"\"))

with cmd
.ActiveConnection = dataConn
.CommandText = "User_Details"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@username", adVarChar, adParamInput, 50, username)
.Parameters.Append .CreateParameter("@code", adInteger, adParamOutput, , 0)
end with
rsUser = cmd.Execute


but it doesn't. i'm hoping one of you guys could show me the light.
thanks heaps,
bronson

Pumpkins_Man
Starting Member

20 Posts

Posted - 2002-07-11 : 19:20:07
okay. i'm a git. i forgot a .Open in there so i'm getting the first lot of data into the recordset but i still can't find out how i can read in or out the code that comes out in the second resultset.

http://www.users.bigpond.com/thefullmontybronty
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-07-11 : 19:30:45
you should find a nextrecordset method on rsUser

rsUser.nextrecordset

==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-07-11 : 19:32:24
Here's an example of how to do what you want. I'm pretty sure you need the NOCOUNT stuff in there. ADO doesn't always give you the right dataset without the NOCOUNT stuff. I forget the particulars, but try it with and without NOUCOUNT, see what happens.

SET NOCOUNT ON
DECLARE @MyTable table(MyField VARCHAR(50))
DECLARE @TotalRecs INT

INSERT INTO @MyTable(MyField) VALUES('lskdfdkslj')
INSERT INTO @MyTable(MyField) VALUES('reewrewrweraerasdrf')
INSERT INTO @MyTable(MyField) VALUES('gfgdfdsf')
INSERT INTO @MyTable(MyField) VALUES('lskdfdkslj')
INSERT INTO @MyTable(MyField) VALUES('sfddsfdsafsaree')

SELECT @TotalRecs = Count(*) FROM @MyTable
select mt.*, @TotalRecs AS TotalRecords FROM @MyTable mt

SET NOCOUNT OFF


RESULT SET:
MyField TotalRecords
--------------------------------- ------------
lskdfdkslj 5
reewrewrweraerasdrf 5
gfgdfdsf 5
lskdfdkslj 5
sfddsfdsafsaree 5


MichaelP


<Yoda>Use the Search page you must. Find the answer you will.
Go to Top of Page

Pumpkins_Man
Starting Member

20 Posts

Posted - 2002-07-11 : 19:54:55
nr, i tried rsUser.nextrecordset but that doesn't seem to be an asp command.

MichaelP, thanks for your way of doing that. I will suggest that the SQl developer does that when he gets back. trouble is in the meantime i am stuck with the procedure and i really need to be able to use it otherwise my security is going to be killed.

http://www.users.bigpond.com/thefullmontybronty
Go to Top of Page

Pumpkins_Man
Starting Member

20 Posts

Posted - 2002-07-11 : 19:56:56
nahg on nr, i was wrong there. nextrecordset would probably work but there doesn't appear to be one cause i get this error.

Object or provider is not capable of performing requested operation.

http://www.users.bigpond.com/thefullmontybronty
Go to Top of Page
   

- Advertisement -