Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 14th, 2003, 12:29 PM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default date column

I want to add a date column to a table. I'd like the default date value in this column to be the same as the date in another date column in the same table. How do I do that?
 
Old June 14th, 2003, 01:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can't.

A DEFAULT constraint may only be a constant expression or a system function, such as getdate().

You could do something like interpret a NULL value in the column to mean that the value should be taken as the value in another column, and use the COALESCE function in your queries as, e.g.:

   SELECT COALESCE(yourcolumn,theothercolumn) FROM yourtable ...

Coalesce returns the first non null value in its expression list, so this would return the value of 'yourcolumn' if it has one, otherwise it returns the value of 'someothercolumn'.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old June 14th, 2003, 01:19 PM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a lot.





Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting on date column in XSLT Palwi XSLT 1 March 18th, 2008 07:19 AM
comparing date column with sql server mallikalapati ASP.NET 2.0 Professional 3 March 12th, 2008 06:06 PM
GridView Hidden DateTime Column date conversion babuman ASP.NET 2.0 Professional 0 February 1st, 2007 06:22 PM
Moving date from one column to another mattastic SQL Server 2000 2 October 6th, 2005 03:16 PM
SQL Server date column and ASP treadmill SQL Server 2000 1 July 7th, 2003 08:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.