Ashok
Ashok

Reputation: 5655

Query for padding a string in SQLite in iOS

I'm working on iPad app which has SQLiteDB as a backend.

I'm searching for string padding concepts in sqlite queries.

Can any one provide sqlite query for below data.

Need to fill the empty spaces with the character 'Y', and Need to apply the padding with character 'Y' up to 20 characters.

For Example.

If Input Column's value String is : YY YN

Then Output Column's value String Should be: YYYYNYYYYYYYYYYYYYYY

Please assume the column name is 'size' and the table name is 'sizetable'.

I just need a query which supports on sqlite , No objective-C coding.

Any comments or suggestions would be appreciated.

Thank you in advance.

Upvotes: 0

Views: 276

Answers (1)

CL.
CL.

Reputation: 180060

  1. Append enough 'Y' characters to pad out even the shortest possible string;
  2. truncate it to 20 characters:
SELECT substr(size || 'YYYYYYYYYYYYYYYYYYYY', 1, 20) FROM sizetable

Upvotes: 1

Related Questions