I'm aware of the option to output a query formatted as JSON, like the following example from the from MSDN page:
SELECT name, surname
FROM emp
FOR JSON AUTO
There are a lot of samples on how to use the resulting json from apps but my question is, how can I store the resulting json in a varchar variable, let's say to store in another table?
DECLARE @Json nvarchar(MAX) = (
SELECT name, surname
FROM emp
FOR JSON AUTO
);
Dan Guzman replied in the MSDN Forum with this neat solution, which corresponds also to @FDavidov's suggestion in his last comment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With