Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8778457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:32:36+00:00 2026-06-13T19:32:36+00:00

Let’s say i’ve got a databasetable looking a bit like this, containing information about

  • 0

Let’s say i’ve got a databasetable looking a bit like this, containing information about some assignments.

Id   | ProfessionId      | Title       | Deadline     | DateCreated | ClosingDate
1    |  5                | Something   | 01-12-2012   | 05-11-2012  | 12-11-2012
2    |  6                | Something   | 01-12-2012   | 05-11-2012  | 12-11-2012
3    |  7                | Something   | 01-12-2012   | 05-11-2012  | 12-11-2012
4    |  7                | Something   | 01-12-2012   | 05-11-2012  | 12-11-2012

I want to generate an overview foreach profession (assignments belong to a certain profession) and count the number of assignment in each profession. The overview coming from the database should look like this;

Id | Name           | FriendlyUrl     | Ordinal   | NumberOfAssignments
5  | Profession 1   | profession-1    | 1         | 1
6  | Profession 2   | profession-2    | 1         | 1
7  | Profession 3   | profession-3    | 1         | 2
8  | Profession 4   | profession-4    | 1         | 0

I’ve currently got a stored procedure returning the overview above, except that the amount of assignments isn’t correct. Assignments with a closingdate in the past (we then assume the assignment is closed) shouldn’t be taken into the the total number of assignment.

The current stored procedure is like this:

BEGIN
    SELECT  p.Id, 
            p.Naam, 
            p.FriendlyUrl, 
            p.Ordinal, 
            COUNT(a.ProfessionId) AS NumberOfAssignments
    FROM ME_Profession AS p 
    LEFT OUTER JOIN ME_Assignment AS a ON a.ProfessionId = p.Id
    INNER JOIN ME_Client AS c ON a.ClientId = c.Id
    INNER JOIN aspnet_Membership AS m ON m.UserId = c.UserId
    WHERE m.IsApproved = 1 
    GROUP BY p.Id, p.Naam, p.FriendlyUrl, p.Ordinal
END

I’ve already came up with and modified procedure like the one below, but it doesn’t work. It feels like i’m either thinking too difficult or missing something obvious. What could go wrong?

SELECT        p.Id, p.Naam, p.FriendlyUrl, p.Ordinal, pc.NumberOfAssignments
FROM            ME_Profession AS p 
INNER JOIN ME_Assignment AS a ON a.ProfessionId = p.Id 
INNER JOIN ME_Client AS c ON a.ClientId = c.Id
INNER JOIN aspnet_Membership AS m ON m.UserId = c.UserId
INNER JOIN (SELECT a2.ProfessionId, COUNT(*) AS NumberOfAssignments FROM ME_Assignment AS a2 GROUP BY a2.ProfessionId WHERE a2.Closingdate > GETDATE()) pc ON p.ProfessionId = pc.ProfessionId
WHERE        m.IsApproved = 1 AND a.Closingdate > GETDATE()
GROUP BY p.Id, p.Naam, p.FriendlyUrl, p.Ordinal

UPDATE 1: Added where condition for date

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:32:37+00:00Added an answer on June 13, 2026 at 7:32 pm

    I don’t think that you need to join against the table ME_profession again, try this:

    SELECT  p.Id, p.Naam, p.FriendlyUrl, p.Ordinal, pc.NumberOfAssignments,
            COUNT(CASE WHEN ClosingDate > GETDATE() OR ClosingDate IS NULL THEN 1 END) AS NumberOfAssignments 
    FROM  ME_Profession AS p 
    INNER JOIN ME_Assignment AS a 
        ON a.ProfessionId = p.Id 
    INNER JOIN ME_Client AS c 
        ON a.ClientId = c.Id
    INNER JOIN aspnet_Membership AS m 
        ON m.UserId = c.UserId
    WHERE (m.IsApproved = 1)
    GROUP BY p.Id, p.Naam, p.FriendlyUrl, p.Ordinal
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say, I have some user input (as a String) like 11010011011. Now I
Let's say I can call a method like this: core::get() . What is the
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say there is a graph and some set of functions like: create-node ::
Let's say I've got a collection of 10 million documents that look something like
Let's say we've got an array of integers: int array = {5, 7, 4,
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Let's say I have this code: <p dataname=description> Hello this is a description. <a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.