473,772 Members | 2,414 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 59425
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
5394
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 cost, and then stick the product into the new cart table.
4
20150
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 decimal although i need two decimal places so it cant be an int. Thanks, Dean
1
20623
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
11614
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 Cast(zip_code as Integer) BETWEEN @lowzip AND @highzip
1
1590
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 next if 101 was used firstby using the int2() function to convert it first. But, of course, I get...
5
27686
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 (dbo_sur_response_answer INNER JOIN dbo_sur_subitem
15
8069
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
8576
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
16490
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
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7460
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
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
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.