Solved

SQL: How to query money field for only values with non-zero in the 'cents' portion?

Posted on 2015-01-23
6
96 Views
Last Modified: 2015-01-24
My donation table looks like this:

id      int
donation  smallmoney
... other fields ...

I wish to run a report selecting ONLY rows where the donation amount has a non-zero in the 'cents' portion of the field. For example, if a row had a donation of 12.66, then I would want to select that row. But if the row had a donation of 12.60, then I would skip that row.

Is such a query even possible? I've been googling with no luck.

Thanks experts!
0
Comment
Question by:rascal
6 Comments
 
LVL 12

Expert Comment

by:FarWest
ID: 40567059
where cast(monyfield as integer) = monyfield
0
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 500 total points
ID: 40567065
I think this will do it, but haven't fully tested it yet:

WHERE donation <> ROUND(donation, 1)

Edit: Yeah, seems to work.
0
 
LVL 35

Expert Comment

by:David Todd
ID: 40567087
Hi,

Try this:
use ExpertsExchange
go

select *
from dbo.SomeTable st
where
	floor( st.SomeColumn ) != ceiling( st.SomeColumn )
;

Open in new window


HTH
  David

PS Scott: why not round to 0 dp?
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40567129
David,

Because the OP indicated:

"if a row had a donation of 12.66, then I would want to select that row. But if the row had a donation of 12.60, , then I would skip that row."
0
 
LVL 35

Expert Comment

by:David Todd
ID: 40567173
Dale,
I guess that I saw cents and missed the explanation of the tens of cents ...
0
 
LVL 1

Author Closing Comment

by:rascal
ID: 40568344
Thanks Scott - yours was the working solution.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

920 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

14 Experts available now in Live!

Get 1:1 Help Now