Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 pleaseeeeeeeee help

Author  Topic 

pkuchaliya
Starting Member

49 Posts

Posted - 2008-07-29 : 08:25:18
hi ,

I have nested query from multiple table, it display near about 20 columns. i also want to count number of returned rows. with same query is it possible.

for example :
suppose a query ---

select id,name,age,salary from employee

then it return 6 rows output.

i also count the row

declare @x as int

select @x=count(*),id,name,age,salary from employee
is it possible

reply


pankaj

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-29 : 08:27:14
[code]select id,name,age,salary from employee
select @x = @@rowcount[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

pkuchaliya
Starting Member

49 Posts

Posted - 2008-07-29 : 08:28:39
Thanks


pankaj
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-07-29 : 08:29:09
[code]
SELECT
e.id
, e.name
, e.age
, e.salary
, rows.total_rows
FROM
employee e
CROSS JOIN (SELECT COUNT(*) AS total_rows FROM employee) rows
[/code]

-------------
Charlie
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-07-29 : 08:30:06
Thought you needed the count to appear as an extra column.

Ignore. use khtan's instead.

-------------
Charlie
Go to Top of Page

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-29 : 08:31:13
Execute both the query,
then u will get two record set,

select id,name,age,salary from employee
select @@rowcount as No_of_count
Go to Top of Page
   

- Advertisement -