Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 need help to update a field into a new field but
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

keesky
Starting Member

2 Posts

Posted - 04/23/2008 :  08:33:18  Show Profile  Reply with Quote
Hello everyone...

I am using SQL Server Enterprise Manger Version 8.0, and I need to update the values of Field one into a new Field of a different type. Here is my example, say I have a table called tblResults with field name "resultOne" and I want to update the values of "resultOne" into a new Field called "resultTwo", but resultOne is of type "nvarchar" and resultTwo needs to be of type "int". I need to run an update query that copies all the values of resultOne into resultTwo? Is there any way I can make the string values to be copied into the int values.

All the values in resultOne have numbers but the type is "nvarchar"?

Hence resultOne has values like 12.09, -100.98, 2827.98 and all of them are numbers, so there must be some way to copy it into resultTwo that is of type "int", I cannot manually do it because i have 35,000 records.

Could someone guide me in the right direction.

Thanks,

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 04/23/2008 :  08:38:11  Show Profile  Reply with Quote
try using CAST function

UPDATE Table
SET resultTwo=CAST(resultOne as int)
Go to Top of Page

keesky
Starting Member

2 Posts

Posted - 04/23/2008 :  09:01:17  Show Profile  Reply with Quote
Hi thats the function works perfectly, thanks very much
Go to Top of Page

chandan_joshi80
Starting Member

India
30 Posts

Posted - 04/24/2008 :  05:47:38  Show Profile  Reply with Quote
UPDATE TEMPTABLE2
SET COL2 = CONVERT(INT,S.COL2)
FROM TEMPTABLE2 t, MASTERTABLE2 s
WHERE t.COL1 = s.COL1

chandan Joshi
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000