Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i get the rowcount of table variables?

Tags:

sql

sql-server

how do i get the rowcount of table variables?

like image 386
subs Avatar asked Mar 17 '11 05:03

subs


Video Answer


2 Answers

If you mean SQL Server table variables, it's just like a normal table:

DECLARE @Foo TABLE
(
  foo int
);

insert into @Foo values (1);
insert into @Foo values (1);
insert into @Foo values (1);
insert into @Foo values (1);

select COUNT(*) from @Foo;
like image 188
squawknull Avatar answered Oct 13 '22 13:10

squawknull


SELECT COUNT(*) OVER ( ) AS 'RowCount' FROM @yourTableVariable

works perfect for table variables!

like image 20
Géza Avatar answered Oct 13 '22 14:10

Géza