Solved

SQL CAST Statement in INSERT - Values show differently in table

Posted on 2007-03-22
6
4,086 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
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…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

757 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

23 Experts available now in Live!

Get 1:1 Help Now