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
 How to print row numbes to output to my reprot

Author  Topic 

Pasi
Posting Yak Master

166 Posts

Posted - 2014-02-11 : 14:51:17
HI,

I am trying to print row numbers in my output report how can I do this? here is my store procedure:
Thanks.
Pasi

AS
BEGIN
select distinct group_name,
mstr_list_item_desc,
person_nbr,
cpt4_code_id,
p.person_id,
p.last_name,
p.first_name

from person p
inner join person_payer pp on pp.person_id =p.person_id

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-02-11 : 14:59:58
Check out the ROW_NUMBER() function.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Pasi
Posting Yak Master

166 Posts

Posted - 2014-02-11 : 16:11:12
Didn't see any relevant post there?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-02-11 : 16:21:12
Google it or look it up in Books Online.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2014-02-12 : 04:26:04
how about select @@rowcount?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-02-12 : 12:09:31
How does @@rowcount help add numbers to each row without adding a bunch of unnecessary code?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

alexsts
Starting Member

13 Posts

Posted - 2014-02-12 : 13:39:22
quote:
Originally posted by Pasi

Didn't see any relevant post there?


How do you form your report?
If you have loop anywhere to display results from that select you can easily add new column with value id=id+1.
If you have it in Crystal then it will take for you new function to represent count for the row.
To see some code of how you use result set to display data would be helpful to answer your question.

Alex
Go to Top of Page

maunishq
Yak Posting Veteran

71 Posts

Posted - 2014-02-12 : 14:54:13
ROW_NUMBER() OVER (PARTITION BY group_name ORDER BY order_list)
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2014-02-12 : 20:32:15
ooo, see wrongly, i thought OP want the total number of record.
Go to Top of Page
   

- Advertisement -