I am using the following select statement in a stored procedure to get data from a table, with a function that returns a JSON for one of the columns. What am I doing wrong in my query?
The function GetRecordComments requires two parameters, with the first one being the RecordID of each row. When I use this query though, I get the following error. How can I call the function passing the recordID as parameter for each row?
Query:
SELECT
RercordID, Name, Region,
dbo.GetRecordComments((SELECT RecordID
FROM RecordList
WHERE RecordID = a.RecordID), 1),
[Address],
dbo.GetRecordComments((SELECT RecordID
FROM RecordList
WHERE RecordID = a.RecordID), 2)
FROM
RecordList AS a
Error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
.., Region, dbo.GetRecordComments(RecordID, 1), [Address], ..?