?
Solved

T-SQL Query

Posted on 2010-11-21
7
Medium Priority
?
995 Views
Last Modified: 2012-05-10
Hi Guys,
 

I am using SQL 2008 R2

Data inside the table itself is in this format.  DataType is Float but I want to convert it nvarchar.

Below numbers are scan numbers, I need to get first 14 digits. I am not sure why its not converting.


and while query executing I am getting this error

Arithmetic overflow error converting expression to data type nvarchar.

SCAN_NUMBER
7.57405132047687E+110
7.67386438024476E+110
7.75606337064184E+110
1.52091641516934E+112
1.55003834319573E+112
1.5566142624275E+112
1.56319018165926E+112
1.64304062947358E+112
1.67216255749997E+112
1.67873847673174E+112
1.68437497893039E+112
1.70034506849326E+112
3.10759202265634E+112
3.53596618975429E+112
1.10700922266828E+113
3.14963940770804E+120

SELECT convert (nvarchar (14), CONVERT (BIGINT,[SCAN_NUMBER])) as SCAN_NUMBER

   FROM SCAN

  where [SCAN_NUMBER] > 9999999999999

 
Thanks for the help
0
Comment
Question by:Dreamslogic
[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
7 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 600 total points
ID: 34185150
select left(ltrim(str(scan_number, 400)),14) from scan
0
 
LVL 18

Assisted Solution

by:deighton
deighton earned 400 total points
ID: 34187079
The numbers are too large for a BigInt by a massive factor

when you say you want the first 14 digits, you realise that some of those numbers are over 120 digits in non scientific notation, do you also want the exponent part?

example

3.14963940770804E+120

what do you want here?

3.1496394077080E+120

3.1496394077080

31496394077080000000000000000000... (etc!)


0
 
LVL 2

Expert Comment

by:vasureddym
ID: 34187748
deighton is correct. the numbers are way too big.

can you please clarify why you just need the first 14 digits? please clarify the objective.
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 

Author Comment

by:Dreamslogic
ID: 34191409
Some reason in the datadase thi scolumn has been stored  as float and the valid numbers are only first 14digits, remaining zeros are not required. Its creating problem in look up, I need to convert this column into  nvarchar(14) to work lookup.

Thanks,
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34191450
see first comment again
0
 

Author Comment

by:Dreamslogic
ID: 34191627
No, I don't need the exponent part of the number, just the first 14 digits.

Thanks,
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34191658
dreamslogic,
Are you working middle down or bottom up?
Have you tried the first comment yet?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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 …
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Suggested Courses

777 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