Author |
Topic |
SammyWaslow
Starting Member
9 Posts |
Posted - 2006-08-22 : 10:31:34
|
I try to set the default value of a column 'DateAdded' to ISNULL(dateAdded,getdate())However, this results in an errormsg. Why is that ?I suspect the column name is not recognized as such? How Do I format the column name (DateAdded) ? |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-08-22 : 10:43:26
|
you set the default value to Getdate() not isnull(...)Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
SammyWaslow
Starting Member
9 Posts |
Posted - 2006-08-22 : 11:07:15
|
I know that!But what I want is to set the default value to getdate() only if the column is null! |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-08-22 : 11:31:09
|
huh?with default value the column will never be null...Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
SammyWaslow
Starting Member
9 Posts |
Posted - 2006-08-22 : 11:38:00
|
The idea is that on record creation getdate() is executed as defaultvalue for DateAdded. After that the value may not be updated! |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-22 : 11:53:22
|
You want the column to be "read-only"?Create a trigger that denies all changes to the column.(I can't believe I am suggesting this...)Peter LarssonHelsingborg, Sweden |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-08-22 : 12:19:43
|
why would you want to update it anyway?Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
SammyWaslow
Starting Member
9 Posts |
Posted - 2006-08-23 : 03:29:42
|
Basiscly I want the column to contain the date the record was created (inserted) |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-08-23 : 04:46:04
|
then just put getdate() in the default value.denying approach on the table level is a wrong approach.Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-23 : 05:20:38
|
Oh, you mean (according to your second post)UPDATE MYTABLE SET DATEADDED = GETDATE() WHERE DATEADDED IS NULL?Peter LarssonHelsingborg, Sweden |
 |
|
|