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
 SQL Server Development (2000)
 put year in field as default

Author  Topic 

csphard
Posting Yak Master

113 Posts

Posted - 2005-05-27 : 08:52:51
I created a text field that when a new survey is added I wanted to add the year in YYYY format. That way if the survey is done this year or the next. I would know by who.


nr
SQLTeam MVY

12543 Posts

Posted - 2005-05-27 : 08:59:49
convert(varchar(4),getdate(),112)
datepart(yy, getdate())


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

csphard
Posting Yak Master

113 Posts

Posted - 2005-05-27 : 09:35:10
I tried coping that statement into the Formula in the Design table view on sql2000. That statement gives me an Error.
The error statement reads Error validating the formual for column 'srv_year'
Do you want to edit the formula?
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-05-27 : 10:09:44
Create the table in query analyser

srv_year char(4) not null default convert(varchar(4),getdate(),112)
or
srv_year int not null default datepart(yy, getdate())

Why not save the datetuime it was created instead then you can calculate the year
Created datetime not null default getdate()



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -