?
Solved

SQL CAST Statement in INSERT - Values show differently in table

Posted on 2007-03-22
6
Medium Priority
?
4,449 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
5 Comments
 
LVL 5

Accepted Solution

by:
sphillips1971 earned 500 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

864 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