Skip to content

Ozar.net Developer Blog

Programming in PHP, C, C#, ASP.NET, Java, Objective-C, SQL also for MS SQL Server, Oracle & MySQL Development

Menu
  • Home
  • About
  • Tutorials
  • Contact
  • Privacy
Menu

Use CAST (or CONVERT) to handle Null Date values in Microsoft SQL Server

Posted on February 26, 2010March 27, 2010 by OD

In an SQL Server View, a problem is that the DateTime field has many Null values which is causing a problem with the parsing of the data in MSAccess.

How to I use CAST (or CONVERT) to handle Null Date values in my SQL Server view?

There is a way to use CAST or CONVERT similar to the nz type function in MSAccess to handle null date values but I can’t remember the syntax.

What is happening now is that I get a data mismatch in my MSAccess function when it hits a Null Date value. Can I somehow use the ISNULL or ISDate function? I believe I need to somehow return “” instead of Null.



COALESCE

Returns the first nonnull expression among its arguments.
Syntax

COALESCE ( expression [ ,…n ] )
Arguments

expression
Is an expression of any type.
n
Is a placeholder indicating that multiple expressions can be specified. All expressions must be of the same type or must be implicitly convertible
to the same type.
Return Types

Returns the same value as expression.
Remarks

If all arguments are NULL, COALESCE returns NULL.
COALESCE(expression1,…n) is equivalent to this CASE function:
CASE
WHEN (expression1 IS NOT NULL) THEN expression1 …
WHEN (expressionN IS NOT NULL) THEN expressionN
ELSE NULL
END

Example:

set @dateval = coalesce (InDateVal,'1900-01-01')

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • NSTableView with Core Data Tutorial using NSFetchedResultsController
  • CodeIgniter Wizard – a new PHP CRUD Code Generator for macOS
  • Installing Oracle Database 10g Express Edition and Changing the Default HTTP Port
  • Xcode Tutorial 2 – Putting iAd into your App (The Apple Approved Way)
  • Cocoa Programming: A Quick-Start Guide for Developers

Blogroll

  • All Systems GO
  • GOZmosis
  • Maclord's Blog
  • Ozar.net

Tags

.NET 2008 application ASP.NET basic Beginning best books business Business Objects C# Database Databases Development Edition Guide iPhone Java Java EE learn Learning Microsoft MS SQL Server MySQL Objective-C Programming objects Oracle Part PHP PL/SQL Professional Programming Server Software SQL T-SQL TSQL Tutorial Tutorials Using Video Visual Visual Basic .NET Web Programming Tutorials XCode
© 2025 Ozar.net Developer Blog | Powered by Minimalist Blog WordPress Theme