Solved

Loss of precision using OpenQuery

Posted on 2004-09-07
3
624 Views
Last Modified: 2008-02-01
Hello,

I have created a function which returns records from a linked server using OPENQUERY (text file delimited with ';') into a TABLE variable.

CREATE FUNCTION [dbo].[fct_PremierTable_IMO]()
      RETURNS TABLE
AS
RETURN
(
      SELECT ZPRXSO, ZPRXVT, ZTVARV
      FROM OPENQUERY (IMO, 'SELECT * FROM IMMOS.txt')
)

The target Table variable is as follows:
DECLARE @tTable TABLE
(
                IDENTITE INT IDENTITY (1, 1) PRIMARY KEY NOT NULL,
          ZPRXSO DECIMAL(18,2),       ZPRXVT DECIMAL(18,2),       ZTVARV DECIMAL(18,2)
)

The problem is that the decimal part of the values are lost. For example, 2356 is obtained instead of 2356.58.
I have tried to use VARCHAR instead of DECIMAL without any success.

Please help!

Rishi
0
Comment
Question by:rrishi
3 Comments
 
LVL 5

Accepted Solution

by:
g0rath earned 125 total points
Comment Utility
cross platform work with decimal types can be hard, the simplest approach that works for me 100% of the time is to take the decimal type, multipy by 100 and transfer it as an integer type, then convert at my local point to decimal, money, float or whatever and just divide the set by 100.

Nothing is worse then 10.42 becoming 10.41999999 due to percision issues
0
 
LVL 18

Expert Comment

by:ShogunWade
Comment Utility
what driver are you using in your linked server ?
0
 

Author Comment

by:rrishi
Comment Utility
Thanks a lot, it seems to do the trick!
Im using OLEDB Jet 4.0 driver.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now