December 7, 2009 at 6:25 am
I've got the following line in my insert
case @datewritten when null then getdate() else @datewritten end
This is giving me an error about null value not allowed as a date.
So I looked at the SELECT statement and the datewritten is null
So I added this case to my SQL statement something like
SELECT datewritten, case datewritten when null then getdate() else datewritten end
Both columns are showing null. I modified the case to be;
case when datewritten = null then getdate() else datewritten end
Same results.
Any help would be appreciated.
Joe
December 7, 2009 at 6:41 am
CASE WHEN datewritten IS NULL THEN getdate() ELSE @datewritten END
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
December 7, 2009 at 8:01 am
Chris has given you the right way to code it, but I'll add an explanation. By default any comparison to NULL (=, !=, Like, etc...) returns Unknown, not True or False which is why SQL Server has the IS NULL and IS NOT NULL statements included. This is called three-valued logic and you need to keep this in mind whenever you work with NULL values.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply