CASE command

Posted on 2011-04-29
Last Modified: 2012-05-11
How can I display different message based user input date? I have table field which holds date named completiondate. the field contains a date, null, or default date 1900:00:00:00. I want to give messaage 'Available' if user input date is greater than the completion date or null or default date and 'not available' if user input date is less than the completion date. How can I do it using case when statement?


Question by:ayha1999
    LVL 39

    Expert Comment

    by:Pratima Pharande
    do you want it in query

    Create a store procedure , give the inputdata as paramenter
    ex @indate

    when @indate < completiondate then 'not available'
    Else 'not available'


    From tablename
    LVL 21

    Expert Comment

    by:Alpesh Patel
    Case when date is null then 'Message1' when date = '1900-01-01' then 'Message2' else 'Message3' End
    LVL 9

    Accepted Solution

    It should be like this. We dont have to handle 1900:00:00:00. as it is not practicle for user to supply a date earlier than this.
    CASE WHEN completiondate < @UserDate OR completiondate IS NULL THEN 'Available' 
    'not available' 

    Open in new window

    LVL 7

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now