Solved

Getting rid of exponential notation in queries

Posted on 2011-03-01
3
643 Views
Last Modified: 2012-05-11
I have a data table that has a customer number in it.  This is a number with many digits in it. I'm storing it as a number because that takes less space than a character string.

When I query CUST_ID I get data that looks like this:

1.5004770527e+011

What I want to see is

15004770527

How can I get this? I am using SQL Server 2008

Thanks
0
Comment
Question by:cipriano555
  • 3
3 Comments
 
LVL 10

Expert Comment

by:dwe761
ID: 35007486

select CAST(CUST_ID as varchar(20))
0
 
LVL 10

Expert Comment

by:dwe761
ID: 35007536
By the way, you didn't mention what data type CUST_ID is.  If you chose BIGINT, you probably wouldn't have this problem.  However, if you want all Cust_IDs to be 11 characters with leading zeros, it is common to cast as varchar to add the leading zeros.
0
 
LVL 10

Accepted Solution

by:
dwe761 earned 500 total points
ID: 35007607
You must have it declared as Numeric or Real or Float.
In that case, you'll need to cast it as BIGINT.  
These examples should clarify.

declare @x real
set @x = 15004770527
select @x as x
select CAST(@x as bigint)
select CAST(@x as varchar(20))

go
declare @x bigint
set @x = 15004770527
select @x as x
select CAST(@x as varchar(20))
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

789 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