SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Row Count
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

satheesh
Posting Yak Master

United Kingdom
148 Posts

Posted - 07/30/2013 :  05:38:39  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3707 Posts

Posted - 07/30/2013 :  06:26:03  Show Profile  Reply with Quote
select policy,policynumber,datecreated,Firstname, COUNT(*) OVER() as recordcount from policy
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

United Kingdom
148 Posts

Posted - 07/30/2013 :  06:44:55  Show Profile  Reply with Quote
Thanks James. Its working.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3707 Posts

Posted - 07/30/2013 :  08:28:02  Show Profile  Reply with Quote
You are very welcome - glad to help.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000