Это динамический c запрос
declare @monthstart int=1,@monthend int=12,@strquery varchar(max)=''
while(@monthstart<=@monthend)
begin
SET @strquery=@strquery+', ISNULL(SUM(CASE WHEN month(trans.DocDate) =' +Convert(varchar,@monthstart)+ ' THEN trans.OutQty END), 0.00) as '+SUBSTRING(DateName( month , DateAdd( month , @monthstart , -1 ) ),1,3)+''
SET @monthstart=@monthstart+1
end
print(@strquery)
Ниже выводится требуемый результат
, ISNULL(SUM(CASE WHEN month(trans.DocDate) =1 THEN trans.OutQty END), 0.00) as Jan,
ISNULL(SUM(CASE WHEN month(trans.DocDate) =2 THEN trans.OutQty END), 0.00) as Feb,
ISNULL(SUM(CASE WHEN month(trans.DocDate) =3 THEN trans.OutQty END), 0.00) as Mar,
ISNULL(SUM(CASE WHEN month(trans.DocDate) =4 THEN trans.OutQty END), 0.00) as Apr,
ISNULL(SUM(CASE WHEN month(trans.DocDate) =5 THEN trans.OutQty END), 0.00) as May,
ISNULL(SUM(CASE WHEN month(trans.DocDate) =6 THEN trans.OutQty END), 0.00) as Jun,
ISNULL(SUM(CASE WHEN month(trans.DocDate) =7 THEN trans.OutQty END), 0.00) as Jul,
ISNULL(SUM(CASE WHEN month(trans.DocDate) =8 THEN trans.OutQty END), 0.00) as Aug,
ISNULL(SUM(CASE WHEN month(trans.DocDate) =9 THEN trans.OutQty END), 0.00) as Sep,
ISNULL(SUM(CASE WHEN month(trans.DocDate) =10 THEN trans.OutQty END), 0.00) as Oct,
ISNULL(SUM(CASE WHEN month(trans.DocDate) =11 THEN trans.OutQty END), 0.00) as Nov,
ISNULL(SUM(CASE WHEN month(trans.DocDate) =12 THEN trans.OutQty END), 0.00) as Dec