Correctly Convert SQL Server Floats By Jet

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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes