Solved

Return DBNull if a certain date

Posted on 2007-12-06
3
599 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: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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

730 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