Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

How to convert from CHAR to Numeric in the table
I have imported some data to sql2k from my old system.  Somehow, it imported
invoice amount to char type.

I just created another column called invamt2 type NUMERIC so I can copy or
convert content of invamt which is type CHAR.  There are about 50,000
records.

How can I convert/cast from char type to numeric type ?

Thanks



Report this thread to moderator Post Follow-up to this message
Old Post
Mac
09-29-05 04:23 PM


Re: How to convert from CHAR to Numeric in the table
If the only problem is the column data type, and you know the data
itself is already numeric, then you can just alter the column data type
directly:

alter table SomeTable alter column invamt numeric(10,5)

See "CAST and CONVERT" in Books Online for general information about
data type conversion.

Simon


Report this thread to moderator Post Follow-up to this message
Old Post
Simon Hayes
09-29-05 04:23 PM


Re: How to convert from CHAR to Numeric in the table
If you don't have any dirty data, you can do:

UPDATE tblname
SET invamt2 = CAST(invamt AS numeric(..., ...))

If you do have dirty data, you will get a datatype conversion error from abo
ve and need to clean
your data first.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www. solidqualitylearning
.com/
Blog: http:// solidqualitylearning
.com/blogs/tibor/


"Mac" <mac@hotmail.com> wrote in message news:TSS_e.10727$WT3.7999@trnddc03...
>
> I have imported some data to sql2k from my old system.  Somehow, it import
ed invoice amount to
> char type.
>
> I just created another column called invamt2 type NUMERIC so I can copy or
 convert content of
> invamt which is type CHAR.  There are about 50,000 records.
>
> How can I convert/cast from char type to numeric type ?
>
> Thanks
>


Report this thread to moderator Post Follow-up to this message
Old Post
Tibor Karaszi
09-29-05 04:23 PM


RE: How to convert from CHAR to Numeric in the table
Play around with this

declare @chrValue varchar(50)
select @chrValue ='123.5678'

select  convert(numeric(7,4)
,@chrValue)
GO
declare @chrValue varchar(50)
select @chrValue ='12388888.5678'

select  convert(numeric(12,4
),@chrValue)
GO

http://sqlservercode.blogspot.com/




"Mac" wrote:

>
> I have imported some data to sql2k from my old system.  Somehow, it import
ed
> invoice amount to char type.
>
> I just created another column called invamt2 type NUMERIC so I can copy or
> convert content of invamt which is type CHAR.  There are about 50,000
> records.
>
> How can I convert/cast from char type to numeric type ?
>
> Thanks
>
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
SQL
09-29-05 04:23 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

MS SQL Server archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 12:53 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006