Without knowing too much about how the data is to be consumed, is it possible to use a STRING_AGG to list the comments in a string such as:
@DirectorsInfo nvarchar(100) = (Select STRING_AGG([Comments], ',') from [K2].[SmartBoxData].[FOS_Corp_BoardofDirectorsOwnershipStructure_SMO] where HeaderID = @HeaderId),
That should return the JSON value as "DirectorsInfo":"Comment 1,Comment 2,Comment 3" in the output. There are potentially several ways to solve this depending on how you need the data to display in your output.
@kimh thanks for your reply.
DirectorsInfo":"BVN-12345678901-xyz@abcd.com|BVN-12345678901-xyz@werty.com",
"Guarantor":"NON-INDIVIDUAL_TIN_12133453_100000000|INDIVIDUAL_BVN_12133453_200000000"
}
Considering that the above are the sample payload for the 2 parameters.
Nevertheless, I will try the string_agg method when I am at my desk.
Be careful here - I'm fairly confident that you are not allowed to add your own stored procedures to the K2 database, or to call into the K2 database directly as this will leave you in an unsupported state.
Cheers
Thanks to everyone I found my way around the script, and I am good now.