1

I have a SP called GetDailyData in SQL Server 2008 like:

CREATE PROCEDURE [dbo].[GetDailyData]
   @date datetime
AS
BEGIN
select * from myTable where date >= @date
END

I would like to call the stored procedure in another stored procedure and print the number of returned data. I tried this, but did not work:

Select COUNT(EXEC GetDailyData @date)

How can I perform it? Any help would be appreciated.

Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82
  • 1
    [SQL Server - SELECT FROM stored procedure](http://stackoverflow.com/questions/1492411/sql-server-select-from-stored-procedure) – valex Sep 01 '16 at 15:06
  • 1
    Also to get a count you can use [@@ROWCOUNT](https://msdn.microsoft.com/en-us/library/ms187316.aspx) after EXEC the SP. – valex Sep 01 '16 at 15:08

2 Answers2

0

I used a Table of variable to perform it. Here is the code:

Declare @T Table (Id int,Name varchar(50))
Insert @T Exec [GetDailyData] @date 
select Count(*) from @T
Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82
0

Try this:

EXEC GetDailyData @date
SELECT @@ROWCOUNT
Sagar Shelke
  • 517
  • 3
  • 10