Solved

Getting rid of exponential notation in queries

Posted on 2011-03-01
3
635 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

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.

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 I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

15 Experts available now in Live!

Get 1:1 Help Now