Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to select via last digit in numeric field? 1

Status
Not open for further replies.

devnull4u

ISP
Oct 8, 2003
7
0
0
US
The following statement is attempting to select each record where the numeric MemberID_ field ends in the number 1 and the member belongs to a particular list.

select * from members_ where 'members.MemberID_' like %1 and 'members.List_' = 'listname'

Unfortunately, it seems that the numeric fields don't respond to "like %1".

Can someone point me in the right direction to be able to select a record based on the last digit in a numeric field?

TIA

---
Rick Rountree
 
How about where MemberID_ % 10 = 1 ... ?

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
% is modulo operator. It return remainder after division. So X % 10 returns... last digit, assuming that memberID_ is integer and NOT char/varchar/whatever.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Try"
[code}
select * from members_
where Right(members.MemberID_ , 1) = 1
and members.List_ = 'listname'
[/code]
 
OK, that makes sense and the MemberID_ field is integer (int).

This is the revised statement that works:

select * from members_ where MemberID_ % 10 = 1 and List_ = 'listname'

Thanks!!

---
Rick Rountree
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top