Solved

Getting rid of exponential notation in queries

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql query help 15 52
SQL Server maintenance plan 8 53
find SQL job run average duration 24 54
SQL QUERY 3 33
This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
In this article I will describe the Backup & Restore 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.
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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