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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:40:53+00:00 2026-06-14T18:40:53+00:00

I have an issue where my SQL query will not get rid of null

  • 0

I have an issue where my SQL query will not get rid of null values.

I have tried a myriad of different techniques, but I am a novice.

My desired result is an Order number followed by the date which the status occurs all in one line.

select mo.order_id OrderID,
case when osr.order_status_cd = 120 and osr.create_date is not null then    osr.create_date end as POCreated,
case when osr.order_status_cd = 220 and osr.create_date is not null then osr.create_date end as Ordered,
case when osr.order_status_cd = 300 and osr.create_date is not null then osr.create_date end as Shipped,
case when osr.order_status_cd = 400 and osr.create_date is not null then osr.create_date end as Received,
case when osr.order_status_cd = 500 and osr.create_date is not null then    osr.create_date end as Completed,
from order_status_record osr
inner join msorder mo on mo.order_id = osr.msorder_id

Instead of getting results that look like this:

OrderID POCreated   Ordered     Shipped      Received    Completed
497822  11/18/2012  NULL          NULL        NULL        NULL
497822  NULL       11/19/2012     NULL        NULL        NULL
497822  NULL        NULL       11/19/2012     NULL        NULL
497822  NULL        NULL          NULL     11/19/2012     NULL
497822  NULL        NULL          NULL        NULL     11/19/2012

I want this:

OrderID POCreated   Ordered     Shipped      Received    Completed
497822  11/18/2012  11/19/2012  11/19/2012   11/19/2012  11/19/2012

Do I need to create a virtual table? Do I need an if function? Why do the Nulls still populate?

Any help would be much appreciated.

Thanks,

Andrew

  • 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-14T18:40:55+00:00Added an answer on June 14, 2026 at 6:40 pm

    If you add an aggregate function to each of the CASE statements and then a GROUP BY the records will consolidate into a single row:

    select mo.order_id OrderID,
      max(case when osr.order_status_cd = 120 and osr.create_date is not null then osr.create_date end) as POCreated,
      max(case when osr.order_status_cd = 220 and osr.create_date is not null then osr.create_date end) as Ordered,
      max(case when osr.order_status_cd = 300 and osr.create_date is not null then osr.create_date end) as Shipped,
      max(case when osr.order_status_cd = 400 and osr.create_date is not null then osr.create_date end) as Received,
      max(case when osr.order_status_cd = 500 and osr.create_date is not null then osr.create_date end) as Completed,
    from order_status_record osr
    inner join msorder mo 
      on mo.order_id = osr.msorder_id
    group by mo.order_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an issue with a my SQL query. I need to execute a
I have this issue: first, I execute a SQL query using Java and then
We're using SQL Server 2000 Query Analyser, and one issue we have is that
I most likely have a syntax issue (SQL command and error copied below) -
We have an issue upgrading to SQL Server 2012. I am using the following
I have an issue regarding an recursive count which works well in SQL server,
I have a bit of an issue with my SQL statement. It is a
I rarely use SQL and have a unique issue I need to solve. I
I am having trouble with the following SQL statement. I have had this issue
Strange issue. I have SQL Server running on an EC2 box that I can

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.