• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

taking 7 digits from database

 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am storing a callerid number in a table.I need to get only the last 7 digits
from the callerid and i have to display it.for example if i am storing 043255667778.i have to get 5667778 and to display it.how can i do this?using substring?please help me to do this.

Thanks
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what I understood from your description is that you are storing a caller id in some database table as a varchar. And later, after retrieving you want to display the last 7 digits using substring function.

If this is correct then you can try: (assuming you fetched the string in str variable of type string)

String lastSeven = str.substring(str.length() - 7);
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks.it is working.
[ May 28, 2008: Message edited by: preethi Ayyappan ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternatively, you could do this directly in SQL. Depending on the number of records you are retrieving, this might reduce the network bandwidth consumed by the database query.

http://www.1keydata.com/sql/sql-substring.html
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MS SQL (and perhaps others) also have methods called LEFT and RIGHT. Perhaps you can use those too:
reply
    Bookmark Topic Watch Topic
  • New Topic