473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

convert varchar to decimal


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #1
4 20093
Are you trying to do this comparison at the database level or in your code?
If database, show query. If code, show code.

Ray at home

"Dean G" <bi********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #2
You can use CSng to convert it into a Single, but then make sure the
variable is not empty/numeric before you do the conversion.

If Trim(myVar) <> vbNullString And IsNumeric (myVar) Then
myVarSng = CSng(myVar)
End If

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Dean G" <bi********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #3
thanks manohar that did the trick, i still had to change it from decimal
to float before it would work though, if anyone has the same problem.

Dean

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #4
"Dean G" <bi********@hotmail.com> wrote in message
news:%2********************@TK2MSFTNGP11.phx.gbl.. .
thanks manohar that did the trick, i still had to change it from decimal
to float before it would work though, if anyone has the same problem.


Decimals are weird little creatures in VBScript. Unlike integers, longs,
etc... they are not a recognized variant subtype. Let me qualify that by
saying VarType() will return 14, but TypeName() will fail. Try
TypeName(decimalvalue) and you will receive the following error:

"Variable uses an Automation type not supported in VBScript"

So when performing arithmetic operations, one is forced to convert
decimals to a supported subtype using functions such as CInt,CDbl, and
most importantly CCur. The reason I emphasize CCur is that the currency
subtype is in fact a decimal with 4 point precision, masquerading as a
supported VBScript variant subtype. The problem with CInt is that you
lose data on the conversion and the problem with CDbl is that they
represent approximations of a number. It's beyond the scope of this
thread but basically it has to do with the fact that computers represent
numbers (and everything else) in binary. As such if a number cannot be
represented as the sum of the powers of 2, an approximation is made.

Response.Write 1 - .94
6.00000000000001E-020.99

So when dealing with decimals of precision less than or equal to 4, CCur
is a good choice.
Jul 19 '05 #5

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

Similar topics

1
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
4
by: Rodusa | last post by:
I am having problem to apply updates into this function below. I tried using cursor for updates, etc. but no success. Sql server keeps telling me that I cannot execute insert or update from inside...
5
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? ...
1
by: Woodies_46 | last post by:
Ok i know this is simple but i just don't know the syntax. What I have is a bunch of values and i want to be able to display them as money values with a $ in front. eg. 16000000 1000 160000
1
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...
2
by: kirke | last post by:
Hi, I have a datetime column named dtDateTime. its format is "Oct 27 2006 12:00:00 " I want to group by only date part of it and count my code is $sql1="SELECT ...
4
by: Chris Bordeman | last post by:
I have a DataColumn, want to derive the DbType. I can do column.GetType() but that's a system type, not a db type. How do I convert it to the corresponding type? Thanks much! Chris B.
10
by: satishrajana | last post by:
Hi, My SQL returns a NULL in a datefield if there is no date in that field. If there is a NULL in this column, I want to replace it with spaces in my SELECT statement when I am selecting these...
5
by: arial | last post by:
Hi all, I have a sql .bak file which i need to convert into xml file. can someone help with this? pointing out to some tutorial or some suggetion on how to start? Thak you,
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...

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.