Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Weird E+006

Author  Topic 

snarty
Starting Member

2 Posts

Posted - 2008-03-12 : 20:55:48
I'm trying to CAST an integer to a varchar and I keep getting e+006 in my result set. The reason I need to do this is so that I can combine 2 columns to return a string.

Here is my table:

incomeBracket | lowIncome(int) | highIncome(int)
-----------------------------------------------
1 1000001 5000000
2 5000001 10000000

Here is my query:

SELECT CAST(incomeLow AS varchar) + ' - ' + CAST(incomeHigh AS varchar) AS incomeRange
FROM IncomeBracket_Currency

How can I get my result to look like this:

1000001 - 5000000
5000001 - 10000000

Instead of what it is returning now:

1e+006 - 5e+006
5e+006 - 1e+007

The query works fine for values that have a character length of 6 and less.

Thanks in advance.

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-03-12 : 21:13:30
I can't reproduce it but this is really something you should do at the front-end.
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2008-03-12 : 21:16:06
Select cast(1000001 as varchar(8)) + '-' + Cast(5000000 as varchar(8))

Specify a length for the varchar.



Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

snarty
Starting Member

2 Posts

Posted - 2008-03-12 : 23:12:47
oh sorry I have fixed this problem. On revising my table design I found that the data type was a float and not an int. It works now!

My bad!

Go to Top of Page
   

- Advertisement -