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.
| 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 employeethen it return 6 rows output.i also count the rowdeclare @x as int select @x=count(*),id,name,age,salary from employee is it possible replypankaj |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-29 : 08:27:14
|
[code]select id,name,age,salary from employeeselect @x = @@rowcount[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
pkuchaliya
Starting Member
49 Posts |
Posted - 2008-07-29 : 08:28:39
|
| Thanks pankaj |
 |
|
|
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_rowsFROM employee e CROSS JOIN (SELECT COUNT(*) AS total_rows FROM employee) rows[/code]-------------Charlie |
 |
|
|
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 |
 |
|
|
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 |
 |
|
|
|
|
|
|
|