If I have this valid select part of a statement to work out a distribution of events :
SUM(CASE WHEN CreatedDate BETWEEN Dateadd(month, - 1, getdate()) AND getdate() THEN 1 ELSE 0 END) AS Period, COUNT(LastClientCareCall.ContactId) AS NumberOfClients
I need to add a percentage calculation and my instinct is to append to the end something like ",100/NumberOfClients*Period as PercentageOfPeriod" but this is of course not possible. I could obviously reuse all my formulas and make a very long winded "100/COUNT(LastClientCareCall.ContactId)*SUM(CASE WHEN CreatedDate BETWEEN Dateadd(month, - 1, getdate()) AND getdate() THEN 1 ELSE 0 END)" but wondered if there was a mechanism for using the output of the previously used alias's to achieve something more tidy?
Thanks in advance