SQL Returns Multiple Counters

Posted on Updated on

This SQL can be used to return multiple counters in one record.

    (select count(*) from Courses where FacilityId = 4) as counter1,
    (select count(*) from Facilities)                   as counter2,
    (select count(*) from TeeBoxes where CourseId=9)    as counter3,
    (select count(*) from Holes)                        as counter4
|   | counter1 | counter2 | counter3 | counter4 |
| 1 | 2        | 4        | 5        | 468      |

Use the following SQL to return a list of counters.

create table #tempCounters( myCounter int )
insert into #tempCounters( myCounter )
(select count(*) from Courses where FacilityId = 4) 

insert into #tempCounters( myCounter )
 (select count(*) from Facilities)
insert into #tempCounters( myCounter )
 (select count(*) from TeeBoxes where CourseId=9)
insert into #tempCounters( myCounter )
    (select count(*) from Holes)

select * from #tempCounters
drop table #tempCounters
|   | myCounter |
| 1 | 2         |
| 2 | 4         |
| 3 | 5         |
| 4 | 468       |

Here’s a link to a stackoverflow posting with more examples.

18 thoughts on “SQL Returns Multiple Counters

    school education said:
    2017-03-25 at 12:13 am

    Simply desire to say your article is as astonishing. The clearness in your submit is simply cool and that i could suppose you are knowledgeable in this subject. Well together with your permission let me to take hold of your feed to keep updated with imminent post. Thank you 1,000,000 and please continue the enjoyable work.

    education advice said:
    2017-03-25 at 3:43 pm

    It’s awesome designed for me to have a web page, which is beneficial for my experience. thanks admin

    education school said:
    2017-03-26 at 11:58 am

    Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

    dep of education said:
    2017-03-27 at 6:21 pm

    Hi there, I check your blog on a regular basis. Your writing style is awesome, keep it up!

    student loans said:
    2017-03-28 at 10:24 am

    Good day! I just would like to offer you a huge thumbs up for the excellent information you have here on this post. I am returning to your website for more soon.

    health problems said:
    2017-03-28 at 9:07 pm

    I’m gone to say to my little brother, that he should also pay a visit this blog on regular basis to get updated from latest reports.

    health care related articles said:
    2017-03-29 at 4:10 pm

    This is a topic which is close to my heart… Many thanks! Where are your contact details though?

    http://www.Gameroids.com/mortal-kombat-x-hack said:
    2017-04-18 at 8:38 am

    It’s challenging to find well-informed individuals on this topic, but you seem like you comprehend what you’re talking about!

    growtopia hack tool said:
    2017-04-19 at 2:54 am

    Good information. Blessed me I reach on your site
    by accident, I bookmarked it.

    Ernestine said:
    2017-04-23 at 4:49 am

    Thanks for the excellent advice, it actually is useful.

    mortal kombat x hack tool said:
    2017-04-24 at 3:11 am

    This is a subject close to my heart cheers. Thanks

    Web Scripts said:
    2017-09-07 at 9:33 pm

    very nice post, i surely really like this site, keep on it

    Bhagwat Katha said:
    2017-09-09 at 9:43 pm

    Woh I like your blog posts, bookmarked ! .

    Classifieds Script said:
    2017-09-11 at 8:45 am

    Very good post, thanks a lot for sharing. Do you happen to have an RSS feed I can subscribe to?

    cheap logo said:
    2017-09-16 at 4:11 pm

    I’d have to talk with you here. Which is not something It’s my job to do! I love reading an article that could make people believe. Also, many thanks permitting me to comment!

    banners said:
    2017-09-22 at 10:06 am

    Thanks for all of your work on this blog. My mother really loves managing investigations and it’s really obvious why. A lot of people know all of the compelling method you create very important strategies on this web blog and as well recommend response from visitors on the matter so my daughter is now studying so much. Take pleasure in the rest of the new year. Your carrying out a fantastic job.

    Jack said:
    2017-10-14 at 9:07 am

    Just a smiling visitor here to share the love (:, btw great style and design. “The price one pays for pursuing a profession, or calling, is an intimate knowledge of its ugly side.” by James Arthur Baldwin.

    hitfilm ignite pro 2017 crack said:
    2017-10-22 at 5:12 pm

    Great, google took me stright here. thanks btw for post. Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *