spcurtis81
spcurtis81

Reputation: 285

SQLite TRIM same character, multiple columns

I have a table in an SQLite db which has multiple columns with leading '='. I understand that I can use...

SELECT TRIM(`column1`, '=') FROM table;

to clean one column however I get a syntax error if I try for example, this...

SELECT TRIM(`column1`, `column2`, `column3`, '=') FROM table;

Due to incorrect number of arguments.

Is there a more efficient way of writing this code than applying the trim to each column separately like this?

SELECT TRIM(`column1`,'=')as `col1`, TRIM(`column2`,'=')as `col2`, TRIM(`column3`,'=')as `col3` FROM table;

Upvotes: 0

Views: 911

Answers (1)

Joe Taras
Joe Taras

Reputation: 15379

How SQLite guide tells:

trim(X,Y)

The trim(X,Y) function returns a string formed by removing any and all characters that appear in Y from both ends of X. If the Y argument is omitted, trim(X) removes spaces from both ends of X.

You have only two parameters, so it's impossible apply it one shot on 3 columns table.

The first parameter is a column, or variable on you can apply trim. The second parameter is a character to change.

Upvotes: 1

Related Questions