Tips & Tricks – Trim method in Microsoft Dynamics NAV (Microsoft Business Solutions-Navision)

My Tip & Trick help you to implement Trim function in C/AL for Microsoft Dynamics Nav.

Trim

Removes all white-space characters from the start and end of a string.

You can use the C/AL function DELCHR with the following syntax:

NewString := DELCHR(String [, Where] [, Which]) 

So, you can use the following code:

String := DELCHR(String,'<>',' ');

TrimStart or LTrim

Removes all white-space characters from the start of a string.

String := DELCHR(String,'<',' ');

TrimEnd or RTrim

Removes all white-space characters from the end of a string.

String := DELCHR(String,'>',' ');

NOTE:
Since “spaces” are used as the default for Which, we can skip second parameter and write code like this:

String := DELCHR(String,'<>');

Do you think that my Tip & Trick is useful? Leave a reply.

Microsoft Dynamics NAV – “The following ODBC error occurred: Error: [Microsoft][ODBC Driver Manager] Invalid string or buffer length State ID: HY090”

—————————
Microsoft Dynamics NAV Development Environment
—————————
The following ODBC error occurred:

Error: [Microsoft][ODBC Driver Manager] Invalid string or buffer length
State ID: HY090
—————————
OK
—————————

When you try to read a Microsoft Dynamics NAV (formerly Microsoft Business Solutions Navision) BLOB Data Type field with an ODBC connection or simply to do a Backup of Navision show the following this error message:

Invalid string or buffer length

Cause:

When you use Microsoft Dynamics NAV BLOB field with Compressed Property to No and SubType Property to Memo is possible to write values from 4 bytes to 2 GB.

Solution:
Write something (like 4 spaces) in the field to cover the 4 byte in all the rows with blob field containing less then 4 bytes.

You can run a query in SQL Server like this:

SELECT *
FROM [TableName]
where DATALENGTH([ImageColumn]) < 4

Did my solution solve your problem? Leave a reply.