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
 Row Count

Author  Topic 

satheesh
Posting Yak Master

152 Posts

Posted - 2013-07-30 : 05:38:39
Hi All,

I want to show the number of rows returned by a select query in the result.

e.g. select policy,policynumber,datecreated,Firstname, '-' as recordcount from policy

If it returns 5 rows, then the 'recordcount' need to show '5' in all row in the result

OutPut

0y96788,HGYG564,29/07/2013,SAM,5
FJUFBN7,JLPIO67,29/07/2013,Test,5
...
..
..

How can i get this number in the result.

Any help will be highly appreciated.

Thanks

Regards,
SG



James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-30 : 06:26:03
[code]select policy,policynumber,datecreated,Firstname, COUNT(*) OVER() as recordcount from policy [/code]You might want to use a PARTITION BY clause in the OVER() construct if you want to group the count.
Go to Top of Page

satheesh
Posting Yak Master

152 Posts

Posted - 2013-07-30 : 06:44:55
Thanks James. Its working.
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-30 : 08:28:02
You are very welcome - glad to help.
Go to Top of Page
   

- Advertisement -