473,748 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 20143
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********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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********@hot mail.com> wrote in message
news:%2******** ************@TK 2MSFTNGP11.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(decima lvalue) 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.0000000000000 1E-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
20622
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
9269
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 a function and it gives me an option that I could write an extended stored procedure, but I don't have a clue of how to do it. To quickly fix the problem the only solution left in my case is to convert this recursive function into one recursive...
5
27684
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
1
14641
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
8575
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
12004
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 convert(varchar,J1708Data.dtDateTime,120), count(convert(varchar,J1708Data.dtDateTime,120))
4
29391
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
39107
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 records. Can any of you experts out there help me with a sample SQL.
5
10113
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
8995
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9561
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...
0
9381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8252
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
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
6078
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2217
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.