help on string comparisons

Post Reply
User avatar
damianodec
Posts: 372
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia
Contact:

help on string comparisons

Post by damianodec »

Hi
I have this field in recordset: oRs:Fields("CODICE"):value
Field CODICE in table is CHAR(15) but in oRs object it lost right blanks.
inside table I have due article:
1st article "5224366010"
2nd article "5224366010V10"

when field oRs:Fields("CODICE"):value is "5224366010V10"

Code: Select all

cCdpar = "45224366010"
IF oRs:Fields("CODICE"):value <> cCdpar
    cCdpar = oLgoft:Fields("LGCDPA"):value
endif
 
the IF istruction is false but articles are diferrent.

how can I to solve it? have I to use SET EXACT ON?
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
Marc Vanzegbroeck
Posts: 1102
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium
Contact:

Re: help on string comparisons

Post by Marc Vanzegbroeck »

Can you try with this

Code: Select all

cCdpar = "45224366010"
IF !alltrim(oRs:Fields("CODICE"):value) == alltrim(cCdpar)
    cCdpar = oLgoft:Fields("LGCDPA"):value
endif
 
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
User avatar
damianodec
Posts: 372
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia
Contact:

Re: help on string comparisons

Post by damianodec »

hi Marc, thank you, that's good solution.
But is SET EXACT ON a good solution too?

why CHAR fields in recordest lose right blanks ?
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: help on string comparisons

Post by AntoninoP »

which database are you using? the column is char(15) or varchar(15)?
On our application on SQL Server we have all column "char" and the spaces are not trimmed.
they are trimmed with varchar
User avatar
damianodec
Posts: 372
Joined: Wed Jun 06, 2007 2:58 pm
Location: Italia
Contact:

Re: help on string comparisons

Post by damianodec »

Hi Antonino
Database is BD2 on iSeries IBM and field CODICE is CHAR(15) (not VARCHAR) but when recordset read table chars are trimmed:
Field CHAR(15) in DBU = "123456abc "
field read = "123456abc".
FiveWin for xHarbour 17.09 - Sep. 2017 - Embarcadero C++ 7.00 for Win32
FWH 64 for Harbour 19.06 (MSVC++) Jun. 2019 - Harbour 3.2.0dev (r1904111533)
Visual Studio 2019 - Pelles C V.8.00.60 (Win64)
Post Reply