Recent

Author Topic: [SOLVED] Substrings in ZMSQL  (Read 4111 times)

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
[SOLVED] Substrings in ZMSQL
« on: September 21, 2021, 12:13:08 am »
Dear ALL,

Many dialects of SQL (MySQL, SQLite, etc.) have a handy SUBSTR() function which extract a substring from a string (starting at any position), for example:

Code: Pascal  [Select][+][-]
  1. SELECT SUBSTR(CustomerName, 2, 5) AS ExtractString FROM Customers;

However, the ZMSQL library (https://wiki.freepascal.org/ZMSQL) offers two rather unusual variations of this function, as follows:

Quote
substr_after(source, substring) Returns the part of source that comes after substring. If substring is not found an empty string is returned.

substr_before(source, substring) Returns the part of source that comes before substring. If substring is not found an empty string is returned.
I do not understand how these functions work and have not been able to find any examples. Could some one provides me with a few hints?

Thanks in advance!

With best wishes,

« Last Edit: October 21, 2021, 12:35:30 am by maurobio »
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: Substrings in ZMSQL
« Reply #1 on: September 21, 2021, 07:50:25 am »
mid(expression, from, count) : https://github.com/git-bee/janSQL/blob/master/doc/6_functions.md#64-string-functions
Code: SQL  [Select][+][-]
  1. SELECT string_col, mid(string_col, 2, 5) FROM TABLE
Best regards / Pozdrawiam
paweld

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: Substrings in ZMSQL
« Reply #2 on: September 21, 2021, 01:21:18 pm »
Dear @paweld,

Thanks a lot, it is now clear and it works fine!

With best wishes,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

 

TinyPortal © 2005-2018