Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

T-SQL Query

Posted on 2010-11-21
7
Medium Priority
?
996 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

Technology Partners: 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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

610 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