0

I have stored procedure like this

create store procedure onetimeprocessing  
as
begin
declare @input_data (id int,title varchar(400),topic varchar(400))
insert into @input_data
select id,title,topic from dB

I just want to count number of records in the virtual table @input_data

How should I get the count.Please help me Thanks in Advance

gbn
  • 422,506
  • 82
  • 585
  • 676
Linnet
  • 101
  • 1
  • 3
  • 8

3 Answers3

2
select count(*) from @input_data

or after the insert

select @@rowcount
Dumitrescu Bogdan
  • 7,127
  • 2
  • 23
  • 31
1

Why not just have this?

create store procedure onetimeprocessing  
as
begin
select COUNT(*) as TheCount from dB

Edit

I'm having difficulty understanding why other folk would suggest to load @inputdata first, then count from that. or return an extra result set with @@ROWCOUNT...

gbn
  • 422,506
  • 82
  • 585
  • 676
1

Its available in @@ROWCOUNT:

declare @input_data table (id int,title varchar(400),topic varchar(400))
insert into @input_data select ....

SELECT @@ROWCOUNT
Alex K.
  • 171,639
  • 30
  • 264
  • 288