Solved

Return DBNull if a certain date

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

747 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

11 Experts available now in Live!

Get 1:1 Help Now