Assume the query
SELECT RecordType, COUNT(*) RecordsCount
FROM Records AS
WHERE ...
GROUP BY RecordType returns this table:
------------------------------
|RecordType | RecordsCount |
------------------------------
| 1 | 15 |
------------------------------
| 2 | 10 |
------------------------------
| 3 | 8 |
------------------------------
I've defined those variables:
DECLARE @paymentRecordCount INT = 0;
DECLARE @dataRecordCount INT = 0;
I'm looking for a way to set at once the both variables - @paymentRecordCount variable to the result of the condition where RecordType = 1, and to set the @dataRecordCount variable to the result of the condition where RecordType = 3.
The only way I've found so far is to compute the select query multiple times something like:
select @dataRecordCount = RecordsCount from (select ... from ..) where RecordType = 3
and to do the same for the other variable, like:
select @paymentRecordCount = RecordsCount from (select ... from ..) where RecordType = 1
There is a way to compute the query once and set the both varaibles together?