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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Convert varchar to double/integer

Author  Topic 

aisyah_mohamad
Starting Member

3 Posts

Posted - 2011-07-19 : 04:01:48
Hi all,

i need a quick help. I'm doing a data analysis using sql, from a set of data that was read from a txt file.

Problem is, i used "load data infile" to import the data, hence all data are in varchar format. When i preset the column as int or double, my data were truncated to the first integers before "," or ".".

Hence, i need help in converting all data from varchar to integer.

Say, i have 5 columns; TransactionID, Voucher, AmountCurrency, AmountRM and CreatedBy with 308k lines of data.

I wanted to convert all data in AmountCurrency and AmountRM as integer.

Is it possible to do it in the same table?
Or, would i need to convert the data and transfer them to another table?

Thank you for your help in advance!!

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-07-19 : 09:28:27
ALTER TABLE yourTable
ALTER COLUMN TransactionID INT
Go to Top of Page

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2011-07-19 : 09:33:07
Is the data after the decimal point important to your business needs? In that case use a DECIMAL datatype instead of INTEGER. Remember to specify both a precision and a scale, for example: ALTER TABLE tableName ALTER Column ColumnName DECIMAL(9,2)

OS
Go to Top of Page
   

- Advertisement -