+ Reply to Thread
Results 1 to 5 of 5

SQL - extracing digits from a number

  1. #1
    dave k
    Guest

    SQL - extracing digits from a number

    Is there a way to extract digits from a number using a SQL statement? I want
    to extract the first digit, second digit etc. from a number. I am using SQL
    on an Excel table. In VBA I can do it by casting a number as text and then
    pulling the digits out of the character string.

    Thanks and Happy New Year,

    Dave


  2. #2
    Buck
    Guest

    Re: SQL - extracing digits from a number

    Against an Excel table using JET SQL I think the MID function should
    work:
    "Select mid(field_name,1,1) as CharacterOne from table_name" would pull
    the first character.

    In other flavors of SQL the SUBSTR function would do the same thing:
    Select SUBSTR((field_name,1,1) as CharacterOne from table_name


  3. #3
    dave k
    Guest

    Re: SQL - extracing digits from a number

    That is it! Thanks for the help. It works exactly as I need it.

    Dave


    "Buck" wrote:

    > Against an Excel table using JET SQL I think the MID function should
    > work:
    > "Select mid(field_name,1,1) as CharacterOne from table_name" would pull
    > the first character.
    >
    > In other flavors of SQL the SUBSTR function would do the same thing:
    > Select SUBSTR((field_name,1,1) as CharacterOne from table_name
    >
    >


  4. #4
    onedaywhen
    Guest

    Re: SQL - extracing digits from a number

    Buck wrote:
    > In other flavors of SQL the SUBSTR function would do the same thing


    AFAIK that 'flavor' is proprietary to Oracle. The ANSI standard
    equivalent is SUBSTRING.

    Jamie.

    --


  5. #5
    Buck
    Guest

    Re: SQL - extracing digits from a number

    Jamie: You are probably correct. I work with Microsot, db2, and Oracle
    databases and occassionally I forget what works with what.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1