MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 23rd, 2008, 05:43 AM
jimbo_jnr jimbo_jnr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 5 jimbo_jnr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 13 m 42 sec
Reputation Power: 0
Select Query

Hello,

Is it possible to select from a float type column only the data that has > 2 digits after the decimal point?

i.e. it would return 1.2222222222, 1234.522, 4334334.5454545
but not 1.0, 1234.53

Thanks,

Jimbo

Reply With Quote
  #2  
Old July 23rd, 2008, 06:04 AM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,910 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 10 h 47 m 12 sec
Reputation Power: 279
where data > truncate(data, 2)
see the manual

Reply With Quote
  #3  
Old July 23rd, 2008, 06:47 AM
jimbo_jnr jimbo_jnr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 5 jimbo_jnr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 13 m 42 sec
Reputation Power: 0
Thank you for the reply pabloj.

I am using MS SQL 2000 which throws an incorrect syntax error for your suggestion.

Any other ideas?

Reply With Quote
  #4  
Old July 23rd, 2008, 07:02 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,921 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 58 m 55 sec
Reputation Power: 1022
lol @ pablo suggesting RTFWM (read the wrong manual)

__________________
r937.com | rudy.ca

Reply With Quote
  #5  
Old July 23rd, 2008, 08:00 AM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,910 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 10 h 47 m 12 sec
Reputation Power: 279
Doh ....

For the OP, check BOL (Books On Line) the MsSQL manual

Reply With Quote
  #6  
Old July 23rd, 2008, 08:22 AM
jimbo_jnr jimbo_jnr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 5 jimbo_jnr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 13 m 42 sec
Reputation Power: 0
The only truncate I can find for MSSQL 2000 is truncate table.
I've also tried to cast and convert the floats to varchars which I could then perform string operations on but the precision gets lost.

select convert(varchar(20),data) from table

&

select cast(data as varchar(20)) from table

e.g. both return 259.28 instead of 259.27999999999997


Any help would be appreciated!

Regards

Reply With Quote
  #7  
Old July 23rd, 2008, 08:27 AM
pabloj's Avatar
pabloj pabloj is online now
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,910 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 10 h 47 m 12 sec
Reputation Power: 279
For MsSQL convert() to decimal with the appropriate number of decimals.

Reply With Quote
  #8  
Old July 23rd, 2008, 11:35 AM
jimbo_jnr jimbo_jnr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 5 jimbo_jnr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 13 m 42 sec
Reputation Power: 0
The problem is I need to convert the column from datatype float to decimal and I need to verify that all the float type data will be rounded appropiately.

To do this I need a means of selecting all the data with <2 places after the decimal point before the type alteration so it can manually be checked against the resulting decimal values. All relevant float entries currently contain 8 places following the decimal point e.g. 999.99999997

The following throws an arithmetic overflow error
convert(decimal(8,8),data)???

Reply With Quote
  #9  
Old July 23rd, 2008, 11:37 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,921 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 58 m 55 sec
Reputation Power: 1022
decimal(8,8) means you can store only numbers less than 1, since all the relevant digits are on the right of the decimal point

perhaps you meant DECIMAL(16,8) ?

Reply With Quote
  #10  
Old July 23rd, 2008, 11:47 AM
jimbo_jnr jimbo_jnr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 5 jimbo_jnr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 13 m 42 sec
Reputation Power: 0
Thanks r937 & pabloj!!!

I actually used DECIMAL(18,14) as I just realised the floats have 14 places post the decimal point.

Regards,

Jim

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Select Query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT