mcfly soft
mcfly soft

Reputation: 11645

sql with substring to a special character with sqlite

I have values with following format in a table in sqlite:

AAAAAAAAAA#BBBBBBBBBB

AAAA#BBBBBBBBBB

AAAAAAAAAAAAAAAAA#BBBBBBBBBBB

I would like to create a SQL where I get the following result:

AAAAAAAAAA

AAAA

AAAAAAAAAAAAAAAAA

In other words. I would like to get the substring from 0->character #. How can I do this ?

Upvotes: 2

Views: 2618

Answers (2)

OTTA
OTTA

Reputation: 1081

Never used sqlite but something along the lines of substr(yourfieldname, 1, instr(yourfieldname, '#') -1) should do it.

Upvotes: 1

MarcelFrehe
MarcelFrehe

Reputation: 143

Please try:

SUBSTR(col,1,INSTR(col,'#') -1)

Can be found at: http://www.sqlite.org/lang_corefunc.html

Upvotes: 7

Related Questions