SQL Server: set NULL value to today's value

I have a column EntryDate in a SQL Server database.

How can I set a NULL value to fill it with today's date (server time) if value was not provided in a query?

Answers


Disallow Nulls on the column and set a default on the column of getdate()

/*Deal with any existing NULLs*/
UPDATE YourTable SET EntryDate=GETDATE() WHERE EntryDate IS NULL

/*Disallow NULLs*/
ALTER TABLE YourTable ALTER COLUMN EntryDate DATE NOT NULL

/*Add default constraint*/
ALTER TABLE YourTable ADD CONSTRAINT
    DF_YourTable_EntryDate DEFAULT GETDATE() FOR EntryDate

Need Your Help

Why Pandoc does not retrieve the image file?

knitr rstudio pandoc rmarkdown

On RStudio version 0.98.501 I had a long .Rmd file which was easily converted to html once I clicked KnitHtml button. The Knitting process, as I understand, created several folders including images...

Objective-C switch using objects?

objective-c design-patterns switch-statement

I'm doing some Objective-C programming that involves parsing an NSXmlDocument and populating an objects properties from the result.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.