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
Solved

T-SQL Query

Posted on 2010-11-21
7
989 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
7 Comments
 
LVL 58

Accepted Solution

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

Assisted Solution

by:deighton
deighton earned 100 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
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.

 

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

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

Title # Comments Views Activity
CDC and AOG on MS SQL 2012 13 23
Run an action on recently added records to a table 13 60
MS SQL Server select from Sub Table 14 23
Substring works but need to tweak it 14 13
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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 documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

856 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