?
Solved

CASE command

Posted on 2011-04-29
4
Medium Priority
?
381 Views
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?

thanks

ayha
0
Comment
Question by:ayha1999
4 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35489551
do you want it in query

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

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

End

From tablename
0
 
LVL 21

Expert Comment

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

Accepted Solution

by:
kaminda earned 800 total points
ID: 35489916
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.
SELECT 
CASE WHEN completiondate < @UserDate OR completiondate IS NULL THEN 'Available' 
ELSE 
'not available' 
END

Open in new window

0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 35489999
Thanks
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

864 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