sql server - query return records or count of records -


in application building, in cases, want display set of indicators on dashboard include counts of records. when user clicks on indicators, want display records.

most of time, counts suffice don't want query database , return actual records counts. there write single stored procedure can leverage same select, in 1 case calculate count, , in others return actual records?

you may achieve wither setting parameter , process if/case statements in sproc.

create procedure sptest_return (@countonly bit = 0) begin     if @countonly = 0      begin         select * test_table     end     else     begin         select count(*) [count]  test_table     end end 

if call sptest_return return rows , if call 1 value argument sptest_return 1 show row count.

hope helps.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -