I have two queries in the current page. They are very similar but still returning different number of records. Here is example:
Query 1
SELECT
recid,
cost,
cur_year
FROM Info i
INNER JOIN Extension ex
ON ex.recid = i.recid
AND ex.categoryid = i.categoryid
WHERE cur_year = 2018
AND info_id = 4531
Query 2
SELECT SUM(cost) AS cost_total
FROM Info i
INNER JOIN Extension ex
ON ex.recid = i.recid
AND ex.categoryid = i.categoryid
WHERE cur_year = 2018
AND info_id = 4531
AND cost > 0
Query 1 in this case returns 2 records. Query 2 returns 1 record. I'm wondering if putting these two in SP would be a good idea? Current code has two separate queries and automatically hitting the database twice. My idea is two have one call to database and return two data sets. If anyone have example how this can be achieved please let me know. Thank you.