I want to assign 4 output values based on specific status of a column, while counting how many occurrences of it there are.
For example
Select @someVariable =(Select count(*) as r
from table
join table 2 as t2
on r.id= t2.id
where getdate() between t2.start and t2.end )
adding extra where statement such as and t2.status="somestatus"
works, but this way I have to to same query for eachdifferent status I have, is it possible to reuse that query or somehow sub query assignment of output variables based on t2.status
Just in case my code example is bit messed up (just writing some from memory), what I am trying to do, is count how many columns there are with particular status and fits in time frame.
I've done what I need, by having multiple queries like this in stored procedure, but I don't want to keep it this way.
Aucun commentaire:
Enregistrer un commentaire