Connecting Tech Pros Worldwide Help | Site Map

How to set default value for a datetime column in mssql

Newbie
 
Join Date: Jan 2008
Posts: 10
#1: Feb 1 '08
Hi

I want to set the default value for a datetime datatype column not null as 2000-01-01 00:00:00.000 but the sql is not executing correctly. It is always inserting value as 1900-01-01 00:00:00.000

How to set the default value appropriately.

Appreciate any help.
deepuv04's Avatar
Expert
 
Join Date: Nov 2007
Posts: 202
#2: Feb 5 '08

re: How to set default value for a datetime column in mssql


Quote:

Originally Posted by pks83

Hi

I want to set the default value for a datetime datatype column not null as 2000-01-01 00:00:00.000 but the sql is not executing correctly. It is always inserting value as 1900-01-01 00:00:00.000

How to set the default value appropriately.

Appreciate any help.

hi,

try the following query, probably will help you


declare @t table
(
id int identity (1,1),
name varchar(100),
date datetime default (('2000-01-01'))
)

insert into @t(name,date) values('aaa',getdate())
insert into @t (name) values('bbb')
insert into @t(name,date) values('ccc',getdate())
insert into @t (name)values('ddd')
insert into @t (name,date)values('eee',getdate())

select * from @t

thanks
Newbie
 
Join Date: Jan 2008
Posts: 10
#3: Feb 6 '08

re: How to set default value for a datetime column in mssql


Quote:

Originally Posted by deepuv04

hi,

try the following query, probably will help you


declare @t table
(
id int identity (1,1),
name varchar(100),
date datetime default (('2000-01-01'))
)

insert into @t(name,date) values('aaa',getdate())
insert into @t (name) values('bbb')
insert into @t(name,date) values('ccc',getdate())
insert into @t (name)values('ddd')
insert into @t (name,date)values('eee',getdate())

select * from @t

thanks

Thanks i was able to fetch the details i needed using the convert function.

Thanks
Reply