473,544 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to convert varchar to numeric ?

meh

I have imported data from excel file. When data came to SQL table, the type
of AMOUNT column was varchar. I tried to convert and cast amount type of
amount column to number type but it does not allow me to convert.

What is the best way of importing data into SQL and type stays the same as
it was in excel file ?

Or anyone has any better solution, please let me.

Thanks.
Jul 20 '05 #1
4 59409
Meh,

You need a 2nd column, temporarily at least:

Update MyTable
set fltAmount = cast( vchAmount as float )
where isnumeric( vchAmount ) = 1

Then check the ones that dont update for garbage.

Regards
AJ

"meh" <me**@hotmail.c om> wrote in message news:w1******** **********@nwrd dc01.gnilink.ne t...

I have imported data from excel file. When data came to SQL table, the type
of AMOUNT column was varchar. I tried to convert and cast amount type of
amount column to number type but it does not allow me to convert.

What is the best way of importing data into SQL and type stays the same as
it was in excel file ?

Or anyone has any better solution, please let me.

Thanks.

Jul 20 '05 #2
FYI, that will sometimes fail.

For example:

declare @s varchar(25)
set @s = '-'
select cast(@s as float) where isnumeric(@s) = 1

How try with integer instead of float.

Bye,
Delbert Glass

"Andrew John" <aj@DELETEmistr ose.com> wrote in message
news:3f******** @duster.adelaid e.on.net...
Meh,

You need a 2nd column, temporarily at least:

Update MyTable
set fltAmount = cast( vchAmount as float )
where isnumeric( vchAmount ) = 1

Then check the ones that dont update for garbage.

Regards
AJ

"meh" <me**@hotmail.c om> wrote in message

news:w1******** **********@nwrd dc01.gnilink.ne t...

I have imported data from excel file. When data came to SQL table, the type of AMOUNT column was varchar. I tried to convert and cast amount type of amount column to number type but it does not allow me to convert.

What is the best way of importing data into SQL and type stays the same as it was in excel file ?

Or anyone has any better solution, please let me.

Thanks.


Jul 20 '05 #3
You could create a new table, with the correct datatypes. Then use a select
into query to add the data collected from the import. Use the convert()
functionality to make the varchars integers.

"meh" <me**@hotmail.c om> wrote in message
news:w1******** **********@nwrd dc01.gnilink.ne t...

I have imported data from excel file. When data came to SQL table, the type of AMOUNT column was varchar. I tried to convert and cast amount type of
amount column to number type but it does not allow me to convert.

What is the best way of importing data into SQL and type stays the same as
it was in excel file ?

Or anyone has any better solution, please let me.

Thanks.

Jul 20 '05 #4
"Tim Hinkel" <th*****@orcapa ck.com> wrote in message
news:u40mb.1364 2$e01.26060@att bi_s02...
You could create a new table, with the correct datatypes. Then use a select into query to add the data collected from the import. Use the convert()
functionality to make the varchars integers.

"meh" <me**@hotmail.c om> wrote in message
news:w1******** **********@nwrd dc01.gnilink.ne t...

I have imported data from excel file. When data came to SQL table, the

type
of AMOUNT column was varchar. I tried to convert and cast amount type of amount column to number type but it does not allow me to convert.

What is the best way of importing data into SQL and type stays the same as it was in excel file ?

Or anyone has any better solution, please let me.

Thanks.


You could create a DTS package that coerced the data into the correct format
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.530 / Virus Database: 325 - Release Date: 22/10/2003
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
5383
by: Bill | last post by:
I'm getting the following error: Disallowed implicit conversion from data type varchar to data type money, table 'bill.dbo.cart', column 'price'. Use the CONVERT function to run this query. Does anyone understand this function and how to use it? I'm trying to pull a quantity value from one table, multiply it times a price to get a total...
4
20115
by: Dean G | last post by:
I need to compare two values. one from a text field 'bid' and the other from a field in an sql server database 'maxbid'. The problem is the column in the database has decimal as its data type and i'm getting a type mismatch. does anyone know how to convert 'bid' into decimal from varchar? the field datatype doesnt necessarily have to be...
1
20612
by: Michel | last post by:
Hi again all, I have a small issue. Here's an example dataset : F1 F2 F3 1 0.58 Hi 2 0.70 Hello 3 Fail Bye 4 <Null> Hi
5
11584
by: Anton | last post by:
I have a table of zip codes, some with Canadian zips. I'd like to take a zip code and search for nearby zips. For example: Dim theZip As Integer = textbox1.text ....Parameter.Add(@ziplow, SqlDbType.Int, 5).Value = (theZip - 10) ....Parameter.Add(@ziphigh, SqlDbType.Int, 5).Value = (theZip + 10) SELECT * from ZIPCODES where...
1
1574
by: Robert Fitzpatrick | last post by:
Using pl/pgSQL on 7.4.3, I have a varchar column called unit name in a table that can be numeric, of course. Most of the time, end users will put A, B, C, D, etc. or 101, 102, 103, etc. I am trying to write a function to determine the next available number after the first is given. For instance, so far I have a function that will determine 102 is...
5
27667
by: 2redline | last post by:
I am trying to write a query in access that will pull results that are in the database in a text field and convert to where I can get a average including decimals. Any Ideas? -----------------------Start SQL-------------------------------------- SELECT AVG(CAST(dbo_sur_response_answer.answer_text AS int)) AS avg_correct FROM...
15
8031
by: angellian | last post by:
Sorry to raise a stupid question but I tried many methods which did work. how can I conserve the initial zero when I try to convert STR(06) into string in SQL statment? It always gives me 6 instead of 06. Thanks a lot.
1
8551
by: fatmapatlar | last post by:
I have to convert this script, but i didn't. This is stored procedure of sql. I need to convert to postgresql... if it is possible please help me! Thanks Fatma CREATE PROCEDURE usp_generatetable(@prm_tableID int, @prm_langID int) as
2
16474
by: gowrishankar | last post by:
Hello, I have to convert a alpha numeric value to a numeric value using query. Is there a way to do it. The column data type is Varchar and I am storing alpha numeric values to it. I have to sort the column now. when I say order by it is not comming properly. Need some solution to do it.
0
7420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7602
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7704
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5904
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5291
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4911
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3404
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1837
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
983
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.