How to append text to memo field?
-
12-06-2021 - |
Question
I'm using Advantage Database Server 9.10, and I want to append a text to Memo field.
I tried this way,
UPDATE
myTable
SET
memo = cast(memo as SQL_VARCHAR(max))
+ cast(' Appended string' as SQL_VARCHAR(max))
WHERE
pk = '80'
but it does not work,
anybody know how to do this?
Solution
There is no VARCHAR(MAX)
data type in ADS, but you can cast to SQL_VARCHAR
or SQL_CHAR
instead.
Correct syntax:
UPDATE
myTable
SET
memo = cast(memo as SQL_VARCHAR)
+ cast(' Appended string' as SQL_VARCHAR)
WHERE
pk = '80'
You can find the valid list of data types for CAST and CONVERT in the ads documentation:
http://devzone.advantagedatabase.com/dz/webhelp/Advantage10.1/master_miscellaneous_functions.htm
OTHER TIPS
I think you can write it more simply as:
UPDATE
myTable
SET
memo = memo + ' Appended string'
WHERE
pk = '80'
If the memo
field might be NULL and you don't want the result to be NULL, you can do something like this:
...
SET
memo = ifnull( memo, '' ) + ' Appended string'
...
This works for me, you just have to make sure you allow for enough characters in the VARCHAR()
:
UPDATE
myTable
SET
memo = CONVERT(VARCHAR(8000),memo) + ' Appended String'
FROM
myTable
WHERE
pk = '80'
I added the FROM myTable
because in my project I had to LEFT JOIN
a couple of tables also.