Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Ltrim(rtrim(column_name)) does not work
Message
 
 
To
12/01/2018 10:16:03
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01657158
Message ID:
01657160
Views:
35
>>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).

Antonio,
Thank you very much for the explanation. I didn't think that in my VFP code I was adding chr(13) and chr(10) but I will double check.
Your example with ALLTRIM() and several parameters works in VFP but it is not compatible with SQL Sever (as far as I know). But at least I know what causes the problem
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform