Solved

SQL CAST Statement in INSERT - Values show differently in table

Posted on 2007-03-22
6
4,247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

728 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