Solved

SQL CAST Statement in INSERT - Values show differently in table

Posted on 2007-03-22
6
4,133 Views
Last Modified: 2012-06-21
I am submitting the following statement to our SQL server:

INSERT INTO _Transactions_FULFILLMENT(_Transactions_FULFILLMENT.UID, _Transactions_FULFILLMENT.XID, _Transactions_FULFILLMENT.Company, _Transactions_FULFILLMENT.Client, _Transactions_FULFILLMENT.Account, _Transactions_FULFILLMENT.SubAccount, _Transactions_FULFILLMENT.CallerID, _Transactions_FULFILLMENT.DNIS, _Transactions_FULFILLMENT.CallTime, _Transactions_FULFILLMENT.CallDate, _Transactions_FULFILLMENT.Agent, _Transactions_FULFILLMENT.Disposition, _Transactions_FULFILLMENT.Field_Name, _Transactions_FULFILLMENT.Field_Tel, _Transactions_FULFILLMENT.Field_Message, _Transactions_FULFILLMENT.Field_Notes, _Transactions_FULFILLMENT.Number, _Transactions_FULFILLMENT.CFWDID, _Transactions_FULFILLMENT.Disposition_Transferred, _Transactions_FULFILLMENT.Disposition_Resolved, _Transactions_FULFILLMENT.Disposition_Notification, _Transactions_FULFILLMENT.Disposition_Open) VALUES (NULL, NULL, 'XACT', CAST('1702' AS real), CAST('8002111812' AS real), CAST('0' AS real), '1234567890', CAST('2345678900' AS real), NULL, NULL, NULL, 'Test Call', 'Testy', '1231231231', NULL, NULL, NULL, NULL, '0', '0', '0', '0'); SELECT @@IDENTITY as theid

I cannot change the CAST portions of this query.

What saves in the database is:
CAST('8002111812' AS real), saves as 8002112000. Column type Numeric(12,0)
This field "Account" stores account numbers up to 10 digits in length.

I have a similar problem with:
CAST('2345678900' AS real) - Same setting as above.

It does NOT happen with small numbers - ie: 1702, saves as 1702.

Can someone please help?

Thanks.
0
Comment
Question by:RichardRiga
6 Comments
 
LVL 5

Accepted Solution

by:
sphillips1971 earned 125 total points
ID: 18771698
Richard,

You might want to try casting those values as bigint's instead:

CAST('8002111812' AS bigint)

I tried it through Query Analyzer and it produced the exact number without any trailing zeros or scientific notation.

Good luck!

Scott
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 18771746
You will have to change the cast - it's not at all appropriate for the task. The synonym for REAL in SQL Server is Float(24) which has a precision of only 7 digits - which is why you're seeing the truncation.
The cast should be to the actual type of the target.
0
 
LVL 1

Author Comment

by:RichardRiga
ID: 18771842
The software that is producing the SQL Statement cannot be changed. I was wondering if there is something I can do on my side. The vendor has already stonewalled me. (Trust me, I tried to put this on them first).
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 18771847
you don't appear to need to cast anyway just present the number ..
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 18771855
ps
use scope_identity()  and not @@identity which will not always give you the desired result..
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

776 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