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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:35:45+00:00 2026-06-15T23:35:45+00:00

I work in a law firm with a case management system which links an

  • 0

I work in a law firm with a case management system which links an interface to a SQL db. I am writing queries in SSRS to run reports. I am trying to run a report on case information. Some of the information is right in the “cases” table (or vcases view), but I’m also trying to link information from a “demands_offers” table. Each case can have multiple demands and offers, so I am using a MAX function in a join to extract only the most recent demand record per case. Unfortunately, doing this eliminates cases which have no demands. I need all the cases to show up.

I have tried using a CASE statement nested in the MAX function to convert NULLS or empty fields to a random early date, but I still can’t get all of the cases to appear in the report.

Any ideas? I am a relative newbie with SQL and have no formal training. Any help would be greatly appreciated. You can see the code below. (P.S. I don’t think that I have the rights to create a temporary table.)

SELECT vc.case_number AS "Matter ID", vc.style, vc.atty2_name AS "Handling Attorney", m.max_demands_date, do.demands, do.demands_notes, sa.authorized,      
(SELECT TOP 1 vl.computename        
FROM vcases vca     
LEFT OUTER JOIN case_parties cp     
ON vca.case_sk = cp.case_sk     
JOIN case_parties cpp       
ON cp.parent_sk = cpp.case_parties_sk       
JOIN vlegal_entity vl       
ON vl.legal_entity_sk = cp.entity_sk        
JOIN vlegal_entity vlp      
ON vlp.legal_entity_sk = cpp.entity_sk      
WHERE (vca.case_sk = vc.case_sk) AND (cpp.role_sk = '3557') AND (cp.role_sk = '3986') ) AS "Plaintiff//'s Attorney",        
(SELECT cp.reference_number     
    FROM cases AS ca    
        LEFT OUTER JOIN case_parties AS cp
        ON ca.case_sk = cp.case_sk
    WHERE (cp.role_sk = '3706')     
        AND (ca.case_sk = vc.case_sk)) AS "Claim Number"


FROM        
vcases vc       
LEFT OUTER JOIN     
case_parties cp ON vc.case_sk = cp.case_sk      
LEFT OUTER JOIN     
vlegal_entity vl ON cp.entity_sk = vl.legal_entity_sk       
LEFT OUTER JOIN     
settle_authority sa ON vc.case_sk = sa.case_sk      
LEFT OUTER JOIN         
demands_offers do ON vc.case_sk = do.case_sk        

INNER JOIN      
 (SELECT DISTINCT max(
(CASE WHEN do.demands_date = '' THEN '1/1/1900 00:00:00'
             ELSE do.demands_date
              END)
  ) as "max_demands_date", vc.case_sk       
   FROM vcases AS vc        
   JOIN demands_offers AS do ON vc.case_sk = do.case_sk     
   GROUP BY vc.case_sk) AS m        
  ON vc.case_sk = m.case_sk  AND        
  do.demands_date = m.max_demands_date      

WHERE (vc.closed_ind = 'O') AND (cp.role_sk = '3816') AND (vl.client_number = 'EAS-01') AND (vc.lawtype_code <> 'FA')       
ORDER BY vc.case_number 
  • 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-15T23:35:45+00:00Added an answer on June 15, 2026 at 11:35 pm

    Your query can probably be written to be much more compact and better performing, but to start you off, this is the part that is removing the rows without demands:

    INNER JOIN      
     (SELECT DISTINCT max(
    (CASE WHEN do.demands_date = '' THEN '1/1/1900 00:00:00'
                 ELSE do.demands_date
                  END)
      ) as "max_demands_date", vc.case_sk       
       FROM vcases AS vc        
       JOIN demands_offers AS do ON vc.case_sk = do.case_sk     
       GROUP BY vc.case_sk) AS m        
      ON vc.case_sk = m.case_sk  AND        
      do.demands_date = m.max_demands_date 
    

    It needs to be

    LEFT JOIN      
     (SELECT DISTINCT max(
    (CASE WHEN do.demands_date = '' THEN '1/1/1900 00:00:00'
                 ELSE do.demands_date
                  END)
      ) as "max_demands_date", vc.case_sk       
       FROM vcases AS vc        
       JOIN demands_offers AS do ON vc.case_sk = do.case_sk     
       GROUP BY vc.case_sk) AS m        
      ON vc.case_sk = m.case_sk  AND        
      do.demands_date = m.max_demands_date 
    

    The reason is that an (A INNER JOIN B) keeps records only when it is possible to match rows in A to rows in B. When there is no demand, the derived table (subquery) returns NULL for max_demands_date, which cannot be matched by do.demands_date = m.max_demands_date. This causes the case record to get removed.

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

Sidebar

Related Questions

work on SQL Server 2000. want to Automated Email Notifications using SQL Server Job
I work with SQL Server 2005. I have a start and end date. Ex:
Please advise. I am a lawyer, I work in the field of Law Informatics.
Everyone of us knows the new law which is a pain for developers who
My work on a 6502 emulator is continuing. I've run into some quirks with
I work with a distributed system that has unit and integration tests. I am
Work on C# Desktop project,I have an account on paypal ,From my desktop application
work on asp.net vs 05 C#.Master page header contain the bellow code <script type=text/javascript
Work on asp.net vs05. I have three type of value Like:IsDesign,IsPrinting,IsInstall they are bit
Work on a support helpdesk. New tickets come in and records are created in

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.