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)
 Searching for rounded figures

Author  Topic 

Bex
Aged Yak Warrior

580 Posts

Posted - 2008-12-24 : 06:39:27
I have a table that contains all the refunds that were made against purchased items:

ItemID Refund
1 100
2 134
3 24
4 200
5 223

I have a query that retrieves all the items that have a rounded amount:

select * from items
where substring(cast(refund as varchar(10)), len(I.AmountCharged)-1, 2) = '00'

Is there a way to rewrite this to be more performant and neater? (i.e. not to do a table scan and reduce the number of functions)

Thanks

Hearty head pats

Bex
Aged Yak Warrior

580 Posts

Posted - 2008-12-24 : 06:40:16
sorry - mistake:

substring(cast(refund as varchar(10)), len(refund)-1, 2) = '00'

Hearty head pats
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-12-24 : 06:51:47
quote:
Originally posted by Bex

sorry - mistake:

substring(cast(refund as varchar(10)), len(refund)-1, 2) = '00'

Hearty head pats



Is a rounded figure one which is divisible by 100 in your case ?? Your logic seems to say so. Instead use this,


select * from items 
where refund%100=0
Go to Top of Page

Bex
Aged Yak Warrior

580 Posts

Posted - 2008-12-24 : 06:54:35
Yes, that is correct, and thank you, that works perfectly.

Have a great christmas!

Hearty head pats
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-12-24 : 06:56:59
quote:
Originally posted by Bex

Have a great christmas!

Hearty head pats



Thanks, Merry Christmas :)
Go to Top of Page
   

- Advertisement -