Using Microsoft SQL Server 2022 I have the following error when trying to convert a negative numeric value to a NVARCHAR(MAX)
com.microsoft.sqlserver.jdbc.SQLServerException: An error occurred during the current command (Done status 0). Arithmetic overflow error converting expression to data type nvarchar.
This can be reproduced with the following code:
CREATE TABLE "MY_DB"."MY_SCHEMA"."TEST"
(
[VALUE] FLOAT
);
INSERT INTO "MY_DB"."MY_SCHEMA"."TEST"
VALUES (-0.0123456789);
SELECT CONVERT(NVARCHAR(MAX), "VALUE" , 3)
FROM "MY_DB"."MY_SCHEMA"."TEST"
Strangely this works with non negative values or with NVARCHAR(4000)
but I need NVARCHAR(MAX)
because I then concatenate these values into a long string with STRING_AGG
.
Any solution to this issue?