Sunday, February 19, 2012

Default Value in Date Field

I am trying to put today's date into a DateTime field in a table. Is there
something I can put in the Default Value property of that field to do this?
I used to do this in Access, but can't figure it out in SQL Server.
Thanks in advance,
Chuck Foster
Programmer Analyst
Eclipsys Corporation - St. Vincent Health SystemExample:
use northwind
go
create table dbo.t (
colA datetime not null constraint df_colA default (getdate())
)
go
insert into dbo.t default values
go
select * from dbo.t
go
drop table dbo.t
go
AMB
"chuckdfoster" wrote:

> I am trying to put today's date into a DateTime field in a table. Is ther
e
> something I can put in the Default Value property of that field to do this
?
> I used to do this in Access, but can't figure it out in SQL Server.
> Thanks in advance,
> --
> Chuck Foster
> Programmer Analyst
> Eclipsys Corporation - St. Vincent Health System
>
>|||You can put GETDATE() in the Default Value property.
Jacco Schalkwijk
SQL Server MVP
"chuckdfoster" <chuckdfoster@.hotmail.com> wrote in message
news:u4jXEqZSFHA.1268@.TK2MSFTNGP14.phx.gbl...
>I am trying to put today's date into a DateTime field in a table. Is there
> something I can put in the Default Value property of that field to do
> this?
> I used to do this in Access, but can't figure it out in SQL Server.
> Thanks in advance,
> --
> Chuck Foster
> Programmer Analyst
> Eclipsys Corporation - St. Vincent Health System
>|||create table mytable (
a int,
b smalldatetime default getdate()
)
insert into mytable (a) values (1)
select * from mytable
a | b
___________________
1 | 2005-04-25 15:36:00
"chuckdfoster" <chuckdfoster@.hotmail.com> wrote in message
news:u4jXEqZSFHA.1268@.TK2MSFTNGP14.phx.gbl...
>I am trying to put today's date into a DateTime field in a table. Is there
> something I can put in the Default Value property of that field to do
> this?
> I used to do this in Access, but can't figure it out in SQL Server.
> Thanks in advance,
> --
> Chuck Foster
> Programmer Analyst
> Eclipsys Corporation - St. Vincent Health System
>|||Hi
Use GETDATE() : For current systemdate and
GETUTCDATE() : for current GMT
Aneesh
"chuckdfoster" <chuckdfoster@.hotmail.com> wrote in message
news:u4jXEqZSFHA.1268@.TK2MSFTNGP14.phx.gbl...
> I am trying to put today's date into a DateTime field in a table. Is
there
> something I can put in the Default Value property of that field to do
this?
> I used to do this in Access, but can't figure it out in SQL Server.
> Thanks in advance,
> --
> Chuck Foster
> Programmer Analyst
> Eclipsys Corporation - St. Vincent Health System
>|||Thank you! Those where exactly what I needed!
Chuck Foster
"Kasper Birch Olsen" <kasper@.nospam.com> wrote in message
news:%23g%23JEwZSFHA.2348@.TK2MSFTNGP09.phx.gbl...
> create table mytable (
> a int,
> b smalldatetime default getdate()
> )
> insert into mytable (a) values (1)
> select * from mytable
> a | b
> ___________________
> 1 | 2005-04-25 15:36:00
>
> "chuckdfoster" <chuckdfoster@.hotmail.com> wrote in message
> news:u4jXEqZSFHA.1268@.TK2MSFTNGP14.phx.gbl...
there
>

No comments:

Post a Comment