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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:22:19+00:00 2026-05-14T00:22:19+00:00

My source table looks like this Id StartDate 1 (null) 2 12/12/2009 3 10/10/2009

  • 0

My source table looks like this

Id     StartDate
1      (null)
2      12/12/2009
3      10/10/2009

I want to create a select statement, that selects the above, but also has an additional column to display a varchar if the date is not null such as :

Id     StartDate    StartDateStatus
1      (null)       Awaiting
2      12/12/2009   Approved
3      10/10/2009   Approved

I have the following in my select, but it doesn’t seem to be working. All of the statuses are set to Approved even though the dates have some nulls

        select
             id,
             StartDate,
        CASE StartDate
        WHEN null THEN 'Awaiting'
        ELSE 'Approved' END AS StartDateStatus
        FROM myTable

The results of my query look like :

Id     StartDate    StartDateStatus
1      (null)       Approved
2      12/12/2009   Approved
3      10/10/2009   Approved
4      (null)       Approved
5      (null)       Approved

StartDate is a smalldatetime, is there some exception to how this should be treated?

Thanks

  • 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-14T00:22:19+00:00Added an answer on May 14, 2026 at 12:22 am

    Try:

    select
         id,
         StartDate,
    CASE WHEN StartDate IS NULL
        THEN 'Awaiting'
        ELSE 'Approved' END AS StartDateStatus
    FROM myTable
    

    You code would have been doing a When StartDate = NULL, I think.


    NULL is never equal to NULL (as NULL is the absence of a value). NULL is also never not equal to NULL. The syntax noted above is ANSI SQL standard and the converse would be StartDate IS NOT NULL.

    You can run the following:

    SELECT CASE WHEN (NULL = NULL) THEN 1 ELSE 0 END AS EqualityCheck,
    CASE WHEN (NULL <> NULL) THEN 1 ELSE 0 END AS InEqualityCheck,
    CASE WHEN (NULL IS NULL) THEN 1 ELSE 0 END AS NullComparison
    

    And this returns:

    EqualityCheck = 0
    InEqualityCheck = 0
    NullComparison = 1
    

    For completeness, in SQL Server you can:

    SET ANSI_NULLS OFF;
    

    Which would result in your equals comparisons working differently:

    SET ANSI_NULLS OFF
    
    SELECT CASE WHEN (NULL = NULL) THEN 1 ELSE 0 END AS EqualityCheck,
    CASE WHEN (NULL <> NULL) THEN 1 ELSE 0 END AS InEqualityCheck,
    CASE WHEN (NULL IS NULL) THEN 1 ELSE 0 END AS NullComparison
    

    Which returns:

    EqualityCheck = 1
    InEqualityCheck = 0
    NullComparison = 1
    

    But I would highly recommend against doing this. People subsequently maintaining your code might be compelled to hunt you down and hurt you…

    Also, it will no longer work in upcoming versions of SQL server:

    https://msdn.microsoft.com/en-GB/library/ms188048.aspx

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

Sidebar

Related Questions

For instance, I want to have a html form that looks like this: <table>
I have a table that looks like this: DECLARE @myTable TABLE (country varchar(max), code
How do I Create a table which looks something like this: Estimate Std. Error
I have a 3 tables that look like this: (source: InsomniacGeek.com ) On the
Using a SELECT statement in MS SQL 2005 TSQL, and no source table, just
I have a stored procedure that uses this select statement: SELECT dbo.VendorProgram.id, dbo.VendorProgram.CODE, dbo.Programs.ProgramName
i have a table with hierarchical structure. like this: (source: aspalliance.com ) and table
I've got some data in a table that looks like so: Recipe | Category
my HTML code looks like this <TABLE style= border=0 CLASS=rdThemeDataTable id=dtWardData cellspacing=0> <COL id=wrdActive></COL>
[SSIS 2008 R2] My Control Flow looks like this: Truncate staging table in 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.