Solved

SQL CAST Statement in INSERT - Values show differently in table

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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

930 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

16 Experts available now in Live!

Get 1:1 Help Now