+ 1

SQL: How can I run this query?

I am the following selection statement in a stored procedure to get data from a table, with one of the columns using a function that returns a JSON. I am having trouble writing the query properly. 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 with the recordID for each row. My 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."

22nd Mar 2020, 3:29 AM
Salman Dadabhoy
1 Answer
+ 1
It seems that the RecordID may not be unique in your table, that would be a reason for the subquery to return multiple rows. But you should be able to do it even without the subquery SELECT RercordID, Name, Region, dbo.GetRecordComments(RecordID, 1), [Address], dbo.GetRecordComments(RecordID, 2) FROM RecordList
22nd Mar 2020, 8:31 AM
Tibor Santa
Tibor Santa - avatar