By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,686 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,686 IT Pros & Developers. It's quick & easy.

How to set default value for a datetime column in mssql

P: 10
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.
Feb 1 '08 #1
Share this Question
Share on Google+
2 Replies


deepuv04
Expert 100+
P: 227
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
Feb 5 '08 #2

P: 10
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
Feb 6 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.