0

I have a table with null-able dates. This has a default constraint of getdate(). If a date is not supplied today's date is inserted. However, I want to convert null's to todays date as well.

Is there a way to force the date to today's date when a null is supplied on an insert.

I do not want to change this to a non-nullable field.

5
  • 1
    You'll need to write an AFTER INSERT trigger in that case Commented Nov 4, 2013 at 16:14
  • 1
    have you tried something like ISNULL(DATE, getdate()) Commented Nov 4, 2013 at 16:15
  • Your second two paragraphs contradict each other. Commented Nov 4, 2013 at 16:16
  • Not sure where the contradiction is so let me clarify - I don't want to change the column to non-nullable but I want to force all inserts with a null date to insert today's date instead. Commented Nov 4, 2013 at 16:24
  • The comment by Marc_s led me to the solution...many thanks Commented Nov 4, 2013 at 16:54

1 Answer 1

1

try this code:

  Update table
    set Date =Getdate()
    where date=null
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.