1

I have a column value like

lut00006300.txt  
sand2a0000300.raw

I need to extract only character data from above given column values. I tried the below query and was able to get the first three characters.

select filesize,
substring(Filename  FROM 1 FOR 3) AS Instrument from Collection;

Is there any approach to extract only the characters from the column value leaving the extensions

The results should be :

LUT  
SAND2A
fancyPants
  • 50,732
  • 33
  • 89
  • 96
user1633295
  • 79
  • 1
  • 5

2 Answers2

0

I think below query will helps you.

select filesize,Filename from Collection where Filename REGEXP '[:alpha]';

Refer:- http://dev.mysql.com/doc/refman/5.1/en/regexp.html

Ravichandran Jothi
  • 3,028
  • 11
  • 52
  • 82
0
SELECT
filesize,
UPPER(SUBSTRING_INDEX(SUBSTRING_INDEX(Filename, '.', 1), '0', 1)) AS Instrument
FROM Collection;

This is a dirty solution, since you want to have the 2 in SAND2A.

Read more about the functions here.

fancyPants
  • 50,732
  • 33
  • 89
  • 96