Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Ltrim(rtrim(column_name)) does not work
Message
De
12/01/2018 10:16:03
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01657158
Message ID:
01657159
Vues:
74
This message has been marked as the solution to the initial question of the thread.
>Hi,
>
>Does SQL Server insert anything at the end of a field? I have a table PO Items. I type something in the field (from VFP application) and then press on Enter for some time, to insert a bunch of empty lines. Then save.
>The report of this item will show a bunch of spaces below, even when I use LTRIM(RTRIM(PO_ITEM)) AS PO_ITEM in the SQL Select. If I remove the spaces at the end of the description, the report does not print empty lines. This makes me think that maybe SQL inserts some "invisible" character, like chr(13) at the end. Is it possible?
>
>TIA

Dmitry, if you have some leading or trailing blank lines and INSERT the value into the database, then the characters representing the blank lines will be inserted, also.

If you want to prevent blank lines at the end (or beginning) of the field when you fetch back the data, you may ALLTRIM them, using SELECT ALLTRIM(PO_ITEM, 0, CHR(13), CHR(10), " ") AS PO_ITEM.

Additionally, if you want to prevent the data being stored that way, you may process the value during the insert or update (exactly how will you do that depends on how are you feeding the database).

For instance
m.ODBC = SQLCONNECT("yourConnection")

m.Po_Item = "123" + CHR(13) + CHR(10)

? SQLEXEC(m.,ODBC, "INSERT INTO PO_Items (PO_Item) VALUES (?(ALLTRIM(m.PO_Item, 0, CHR(13), CHR(10), ' ')))")
will store the value without the trailing blank line (but will honor any newline or even any blank line that exists inside the text value).
----------------------------------
António Tavares Lopes
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform