Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy contents of one column into another

Status
Not open for further replies.

btween

Programmer
Aug 7, 2003
338
US
I have a table in a MSSQL db in which I want to copy the contents of a column to another column. The initial column is of the type nvarchar (50) I would like the new one to be datetime (all the values are 4 character numbers) dates, 2004, 2005, 2006, etc.

What Is the procedure for doing this.

thanks for your help

 
This question really belongs in the SQL Server Programming forum forum183 because it has nothing to do with setup or administration.

DateTime fields have a date component and a time component. You can leave the time component 'blank' but with the understanding that it is there (it will be set to midnight). You can't, however, leave the month and day blank. The following query will set the month and day to January 1st.

Code:
Update Table
Set    MyDateField = Convert(DateTime, '01/01/' + OldVarCharField)

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top