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
 count function in stored procedure - newbie

Author  Topic 

cranky franky

12 Posts

Posted - 2009-08-12 : 13:55:52
basic SQL query knowledge. Was handed a stored procedure for a report that needs some tweaks. I use the business development Studio and you can't use the query designer to view the SP. I wish to count the total distinct rows from this procedure based on one field.

My impression is I should be able to do this on the design side and not within the SP. Since I can't use the designer tools it appears I HAVE to run this count within the SP. Correct?

Second question is how to do that. I've tried various methods with no luck.
Sample query from the SP:

select field1, field 2,...field7
from table1
join ...
join ...
join ...
where ....
order by field1, field2

I wish to count the total distinct rows from field1 and put that total on the report. does that make sense?
thanks any help.

cranky franky

cranky franky

12 Posts

Posted - 2009-08-12 : 18:43:20
EDIT TO ORIGINAL: no longer a stored procedure for various reasons, so now the simple question becomes,
how do you count the distinct non-null rows of ONE column in a multi-column table, given COUNT expects every field in the select to be part of the function.

Bogus Data example:
name id type aller reac
smith 1111 A no no
jones 2222 A no yes
stout 3333 B yes yes
see 4444 A no no

I wish to count the total distinct rows from the name column and put that total at the bottom like below:

name id type aller reac
smith 1111 A no no
jones 2222 A no yes
stout 3333 B yes yes
see 4444 A no no
Total 4

the basic query is in the first post. I can be more specific if needed.

Thanks!
franklin
Go to Top of Page
   

- Advertisement -