Solved

Getting rid of exponential notation in queries

Posted on 2011-03-01
3
647 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
[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
  • 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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