Subject: Moving date from one column to another
Posted By: mattastic Post Date: 10/4/2005 6:23:54 AM
Hi,

I need to change a varchar into a smalldatetime datatype.

Problem is my db has 1500 records, so i'm trying to create a new column with the smalldatetime datatype and copy all the data from the old column into here.

Can anybody tell me how to do this in sql server?

I've tried altering the table in design view, but it won't let me save it.

TIA

Reply By: SqlMenace Reply Date: 10/4/2005 7:25:13 AM
alter table Tablename ADD newdatecolumn smalldatetime NULL
Go
update Tablename set newdatecolumn =convert(smalldatetime,Oldvarcharcolumn)
where isdate(Oldvarcharcolumn) =1
go

something like this should do it(untested)

http://sqlservercode.blogspot.com/
Reply By: mattastic Reply Date: 10/6/2005 3:16:19 PM
Thanks


Go to topic 35475

Return to index page 458
Return to index page 457
Return to index page 456
Return to index page 455
Return to index page 454
Return to index page 453
Return to index page 452
Return to index page 451
Return to index page 450
Return to index page 449