Link to home
Start Free TrialLog in
Avatar of rafayansar
rafayansar

asked on

RETURNING RECORDSET FROM SQL SERVER STORED PROCEDURE?

HI EVERYONE,

I want to return a recordset from the Sql Server stored procedure.
The stored procedure is as follows:

// Little description about the stored Procedure is here
I have table named ABC from which i store the data in a CURSOR. And on the data of cursor i want to run another query on table named XYZ whose result i want to return in my ASP.
This procedure is working fine in SQL Server Query analyzer but didn't return any value in ASP.

CREATE PROCEDURE [dbo].[Week52Hi] AS
begin
      declare @Company varchar(30)
      declare @V_MAX(HI) INT
      
-- MY MAIN QUERY
DECLARE RS3 CURSOR FOR
(      SELECT Company, MAX(HIGHEST) MaxHigh
      FROM ABC
      WHERE
      DATE_TIME >= convert(char(12),dateadd(year,-1,getdate()),101) AND
      DATE_TIME < CONVERT(varchar,GetDate()-1,101)
      group by Company
      ORDER BY Company
)

Open RS3
      Fetch from RS3
      INTO @Companye,@V_MAX

while @@fetch_status = 0
 begin
      
      -- MY SUB-QUERY
      SELECT CompanyCode, Hi AS MaxHigh
      FROM ABC where date_time = CONVERT(char,getdate(),101)
      AND CompanyCode=@Company
      AND DATE_TIME = (SELECT Max(Date_Time) FROM ABC WHERE CompanyCode=@COMPANY)
      AND HI > @v_max ORDER BY Company


       Fetch from RS3
       INTO @Company,@v_max
          
 end

close RS3
deallocate RS3

end
GO


Thanx in Advance.
Waiting for your kind replys.

Regards,
Rafay

Avatar of apresto
apresto
Flag of Italy image

You would normally use the command object to do so for example:

            objCmd.Activeconnection = objCon
            objCmd.CommandText = "StoredProcedureName( PARAMETERS )"
            objCmd.CommandType = 04
            objCmd.CommandTimeout = 300
            Set objrs = objCmd.execute

Now the results of the sp are in a recordset called objRs
Avatar of Otana
Otana

If I understand your code correctly, you're executing multiple selects (because of your loop). I think ASP will only get the results of the first select.
Only a gues but there is normally a switch for data retrieval with some control systems, something like ExecuteNoRecords. You might want to check that this isn't switched on.
ASKER CERTIFIED SOLUTION
Avatar of Hilaire
Hilaire
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial