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 688883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:16:31+00:00 2026-05-14T02:16:31+00:00

I am trying to add a CASE statement to the end of my SQL

  • 0

I am trying to add a CASE statement to the end of my SQL query to compute a value depending upon another table value and a previously computed value in the SELECT. The error is returned that DelivCount is an invalid column name. Is there a better way to do this or am I missign something?

SELECT jd.FullJobNumber, jd.ProjectTitle, jd.ClientName, jd.JobManager, jd.ProjectDirector, jd.ServiceGroup, jd.Status, jd.HasDeliverables, jd.SchedOutsideJFlo, jd.ReqCompleteDate,(SELECT COUNT(*)FROM DeliverablesSchedule ds WHERE jd.FullJobNumber = ds.FullJobNumber) as DelivCount, SchedType = 
    CASE 
        WHEN (jd.SchedOutsideJFlo = 'Yes')
            THEN 'outside'
        WHEN (jd.HasDeliverables = 'No ')
            THEN 'none'
        WHEN (DelivCount > 0)
            THEN 'has'
        WHEN (jd.HasDeliverables = 'Yes' AND DelivCount = 0)
            THEN 'missing'
        ELSE 'unknown'
    END
FROM JobDetail jd
  • 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-05-14T02:16:31+00:00Added an answer on May 14, 2026 at 2:16 am

    try this, which should run a lot faster:

    SELECT 
        jd.FullJobNumber, jd.ProjectTitle, jd.ClientName, jd.JobManager, jd.ProjectDirector, jd.ServiceGroup, jd.Status, jd.HasDeliverables, jd.SchedOutsideJFlo, jd.ReqCompleteDate
            ,ds.DelivCount
            ,SchedType =CASE 
                            WHEN (jd.SchedOutsideJFlo = 'Yes')
                                THEN 'outside'
                            WHEN (jd.HasDeliverables = 'No ')
                                THEN 'none'
                            WHEN (ds.DelivCount > 0)
                                THEN 'has'
                            WHEN (jd.HasDeliverables = 'Yes' AND ds.DelivCount = 0)
                                THEN 'missing'
                            ELSE 'unknown'
                        END
        FROM JobDetail jd
            LEFT OUTER JOIN (SELECT
                                 FullJobNumber, COUNT(*) AS DelivCount
                                 FROM DeliverablesSchedule
                                 GROUP BY FullJobNumber
                            ) ds ON jd.FullJobNumber = ds.FullJobNumber
    

    The original query uses a subquery:

    A subquery is a SELECT query that
    returns a single value and is nested
    inside a SELECT, INSERT, UPDATE, or
    DELETE statement, or inside another
    subquery. A subquery can be used
    anywhere an expression is allowed.

    by the very nature of a sub query, it must be run repeatedly, once for each row. I have rewritten the query to use a derived table, which is evaluated one time to find all of the counts and is then joined to the proper rows. This allows for the DelivCount value to be referred to as any column would be when joined from another table, and should speed up this query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view that I am trying to add to my ADO.NET Entity
I'm trying to connect from a web app to another web app using the
In my specific case I have (function(){ and I want to replace that with
I am trying to remove all the NetBeans related files ( nbactions.xml and nb-configuration.xml
I'm trying to create a generic function to build a Linq expression from a
I'm trying to write some test cases for my Qooxdoo application, and I think
I'm trying to use a yui plugin that pulls from a json file and
I'm trying to write a user name validation that has the following restrictions: Must
Hey all, I think this might be a bug, but it's killing me. I
I'm working through Agile Web Development with Rails, Edition 4 with some tweaks (mostly

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.