Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Automatic Update

Author  Topic 

schuhtl
Posting Yak Master

102 Posts

Posted - 2004-02-17 : 14:58:43
Is there a way (other than a scheduled job) to have a field updated automaticlly. What I need is a datetime field to always be 10 day's minus the current date(midnight). If my servers time hits 2/17/2004 00:00:00 AM I would need something to update my datetime field to 2/7/2004 00:00:00 AM.

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-17 : 15:01:00
Why not use a default constraint on the column?

Brett

8-)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-02-17 : 15:01:55
Why don't you want to use a scheduled job? Why do you want the column to be calculated for you? Why don't you calculate it in the query?

Tara
Go to Top of Page

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-02-17 : 15:16:59
If it is always 10 days minus the current date why store it at all??
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-17 : 16:41:11
I betcha he wants to store that value, so it can be used to set the value of a column...

I still think he'll end up with a constraint...


USE NorthWind
Go

CREATE TABLE myTable99 (Col1 int IDENTITY(1,1) NOT NULL
, Col2 datetime NOT NULL
DEFAULT (DATEADD(dd,-10,CONVERT(datetime,CONVERT(varchar(26),GetDate(),101),120)))
, Col3 char(1))
GO

INSERT INTO myTable99(Col3) SELECT 'x'

SELECT * FROM myTable99
GO

DROP TABLE myTable99
GO




Brett

8-)
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2004-02-17 : 21:21:41
Hey, maybe even a trigger would do the trick...kinda hard to tell...

--
Lumbago
"Real programmers don't document, if it was hard to write it should be hard to understand"
Go to Top of Page
   

- Advertisement -