Solved

T-SQL Query

Posted on 2010-11-21
7
980 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
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.

758 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

19 Experts available now in Live!

Get 1:1 Help Now