Solved

Return DBNull if a certain date

Posted on 2007-12-06
3
598 Views
Last Modified: 2012-08-13
In building an ASP.NET project, I have noticed that SLQ Server returns 1-1-1900 as a date when it has no date. How can I write inside a stored procedure a way to return dbnull if the date value is 1-1-1900 ?
0
Comment
Question by:shelbyinfotech
3 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20419825
Case when urDateColumn is null then NULL Else CONVERT(varchar(10), urDate,120)  End
0
 
LVL 10

Accepted Solution

by:
imrancs earned 500 total points
ID: 20419834
SELECT CASE WHEN DateColumn = '1900-01-01' THEN NULL ELSE DateColumn End As [DateColumn]
FROM TableName

Imran
0
 
LVL 12

Expert Comment

by:needo_jee
ID: 20419881
You may use case statement like this

DECLARE @TestVal int
SET @TestVal = 3

SELECT
      CASE @TestVal
            WHEN 1 THEN 'First'
            WHEN 2 THEN 'Second'
            WHEN 3 THEN 'Third'
            ELSE 'Other'
      END
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

789 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