• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

How do you write 2 queries in one stored procedure?

I am looking to write two queries wrapped up into one stored procedure.  How do I do that so I get two results out of one stored procedure?
0
VBBRett
Asked:
VBBRett
4 Solutions
 
tigin44Commented:
basicly a procedure like this may help you


CREATE PROCEDURE XXXX
      @param      tinyint
AS
      
      IF @param = 1
      BEGIN
      -- your first query
      
      
      END
      
      IF @param = 2
      BEGIN
      -- your second query
      END
0
 
Anoo S PillaiCommented:
Please see teh following code snippt.


USE master ;
GO
CREATE PROCEDURE TwoResultSets
AS
SELECT Table_Schema, Table_Name FROM INFORMATION_SCHEMA.TABLES ;
SELECT Table_Schema , Table_Name, Column_Name FROM INFORMATION_SCHEMA.COLUMNS ;
GO

EXEC TwoResultSets  
GO


Does this help you?
0
 
Scott PletcherSenior DBACommented:
CREATE PROCEDURE ...
AS
SELECT ...
FROM ...

SELECT ...
FROM ...


You will have to use code in the receiving app to distinguish one result set from the other.
0
 
VipulKadiaCommented:
CREATE PROCEDURE ...
AS
SELECT ...
FROM ...

SELECT ...
FROM ...

Suppose you have VB.NET as front end application and you fill dataset for above stored procedure then you can get this result like this :
YourDataset.Tables(0) will hold result of first query.
YourDataset.Tables(1) will hold result of second query.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now