Solved

Return DBNull if a certain date

Posted on 2007-12-06
3
601 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Munawar Hussain
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

624 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