How do I get the rowcount value of table variables?

How do I get the value of a row in a variable table?

+4
source share
3 answers

If you mean SQL Server table variables, it's just like a regular 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; 
+10
source
 SELECT COUNT(*) FROM TABLE_NAME; 
0
source
 SELECT COUNT(*) OVER ( ) AS 'RowCount' FROM @yourTableVariable 

works great for table variables!

0
source

Source: https://habr.com/ru/post/1344037/


All Articles