Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
The number in Replicate creates a problem
Message
From
04/04/2022 23:16:53
 
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
01684050
Message ID:
01684056
Views:
44
>>Hi,
>>
>>I am troubleshooting the following issue. And I can't figure out what causes it.
>>
>>A somewhat long SQL Select has the following segment:
>>
>>REPLICATE(' ',10-LEN(ALLTRIM(REFERENCE)))
>>
>>
>>The purpose of the above is to create a string of entity codes (nbsp) equal to the number of spaces after some entry in a field. The field name is REFERENCE. It used to be up to 10 characters in length. And the user was able to enter only up to 10 characters. And the above code worked.
>>Then I increased the length of the field to 15. But the entry in the field is still the same, less or equal to 10 characters.
>>Now the above code does not work. The SQL Select returns the error:
>>
>>String is too long to fit.
>>
>>
>>If I change the 10 in the above REPLICATE with 15, no error.
>>
>>REPLICATE(' ',15-LEN(ALLTRIM(REFERENCE)))
>>
>>
>>I don't understand why? Since the entry in the REFERENCE field is still only up 10 characters, the code 10-LEN... should work. Unless I miss something obvious.
>>
>>TIA for any explanation
>
>I decided that it is easier to run this SQL Select right from the VFP 9 command window, instead of running it from the ASP.NET app. And the result is the same, when running this SQL Select from the command window.
>Here is the entire SQL Select:
>
>select ALLTRIM(REFERENCE) + REPLICATE(' ',15-LEN(ALLTRIM(REFERENCE))) + ' ' + REF_DESCR 
>AS WO_REFER1 FROM WO_REFER
>
>
>If the number in the SQL Select above is 10, I get error. If it is 15, no error. But,
>What is VERY strange to me, is when I can successfully SQL Select the query, the column WO_REFER1 is only about 60 to 62 char in length. It should be wider since the SQL Select concatinats the fields REFERENCE and REPLICATE(ENTITY) AND REF_DESCR field. So, basically only one or two letters from REF_DESCR go into the column WO_REFER1.

What happens if you wrap it in CAST( ) and give it plenty of room:
select CAST( ALLTRIM(REFERENCE) + REPLICATE(' ',15-LEN(ALLTRIM(REFERENCE))) + ' ' + REF_DESCR , C( 120 ) ) ;
AS WO_REFER1 FROM WO_REFER
Are there any NULL values or possible table corruption e.g. CHR( 0 ) in a character column?
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform