Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to return first 3 digits of a number? Curalice Excel Worksheet Functions 3 April 3rd 23 03:45 PM
VBA write macro change column with 3 number digits to 4 digits the James C[_2_] Excel Discussion (Misc queries) 3 January 25th 10 03:12 PM
number 12 digits to 15 digits mehdy-e Excel Discussion (Misc queries) 5 November 13th 09 04:43 PM
Sum of digits in a number Bob Ptacek Excel Worksheet Functions 3 January 8th 08 12:49 AM
How to customize number to 10 digits including 2 digits after deci Carina Excel Worksheet Functions 3 September 20th 07 02:50 AM


All times are GMT +1. The time now is 04:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"