• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 606
  • Last Modified:

Return DBNull if a certain date

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
shelbyinfotech
Asked:
shelbyinfotech
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
Case when urDateColumn is null then NULL Else CONVERT(varchar(10), urDate,120)  End
0
 
imrancsCommented:
SELECT CASE WHEN DateColumn = '1900-01-01' THEN NULL ELSE DateColumn End As [DateColumn]
FROM TableName

Imran
0
 
Munawar HussainPrincipal Software EngineerCommented:
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

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now