Sql server select three different rows in same table with one query -
i have table 2 column(id , span) , 3 different rows id 1,2,3. table looks below:
id span 1 30 2 -30 3 -7
i need these span various id.
declare @leadlookupspan smallint, @notificationresendspan smallint; select @leadlookupspan = span usedcarnotificationconfig id=2; select @notificationresendspan = span usedcarnotificationconfig id=3;
i doing select table check each row everytime. can me optimize query can retrieve span multiple id in 1 go.
you can use conditional aggregation:
declare @leadlookupspan smallint, @notificationresendspan smallint; select @leadlookupspan = max(case when id = 2 span end), @notificationresendspan = max(case when id = 3 span end) usedcarnotificationconfig id in(2, 3);
Comments
Post a Comment