Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2005, 06:23 AM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Moving date from one column to another

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

 
Old October 4th, 2005, 07:25 AM
Authorized User
 
Join Date: Sep 2005
Location: , , .
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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/
 
Old October 6th, 2005, 03:16 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting on date column in XSLT Palwi XSLT 1 March 18th, 2008 07:19 AM
comparing date column with sql server mallikalapati ASP.NET 2.0 Professional 3 March 12th, 2008 06:06 PM
moving a column p_gauri7 Crystal Reports 6 December 20th, 2004 03:27 PM
SQL Server date column and ASP treadmill SQL Server 2000 1 July 7th, 2003 08:51 AM
date column yagiroy SQL Server 2000 2 June 14th, 2003 01:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.