Correctly Convert SQL Server Floats By Jet

When using the SQL Server ODBC driver and SQL Server, and If ODBC preparedexecution is used, certain floating-point values may be incorrectly converted.Microsoft Access and Microsoft Visual Basic commonly use the ODBC preparedexecution. For example:

 Dim db As DatabaseDim ds As DynasetSet ds = db.CreateDynaset("SELECT * FROM test")ds.AddNewds.Fields("col1") = 3.9ds.Update

A query that checks for equality of the float column to the value inserteddoes not show the record inserted, whereas a nonqualified query shows therecord. For example, the record set for the ds1 dynaset does not show therecord inserted, but ds2 dynaset will:

 Set ds1 = db.CreateDynaset("SELECT * FROM test _	WHERE col1=3.9")Set ds2 = db.CreateDynaset("SELECT * FROM test")

The difference in behavior is because, in the case of prepared execution,the ODBC driver is doing the conversion to float. In the case of nonpreparedexecution and DB-Lib client tools, SQL Server is doing the conversion.To work around this problem, do an explicit convert on the SQL Serverusing a statement similar to this:

 UPDATE test SET foo= (CONVERT(FLOAT, _	CONVERT(VARCHAR, col1)))

You can do the same thing within a trigger to automatically update thevalue for all new records inserted. Please note that this problem doesnot occur using the pass-through mechanism because in that case, the conversionis done by SQL Server.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS