Solved

T-SQL Query

Posted on 2010-11-21
7
984 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

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…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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.

863 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

25 Experts available now in Live!

Get 1:1 Help Now