Optimizing query using a WHILE statement I'm trying to convert a view that extracts a yearly amount into something more WHILEish 

The query is more or less:

SELECT *
FROM
(SELECT SUM(EmployeePaid)*2 AS Total2013 FROM TblRecords WHERE FYear = 2013) t1,
(SELECT SUM(EmployeePaid)*2 AS Total2014 FROM TblRecords WHERE FYear = 2014) t2,
(SELECT SUM(EmployeePaid)*2 AS Total2015 FROM TblRecords WHERE FYear = 2015) t3


So this returns:

=====================================
‖ Total2013 ‖ Total2014 ‖ Total2015 ‖
=====================================
‖ 42983.31  ‖ 76345.10  ‖  87233.5  ‖
=====================================


Which is nice and easy to use for generating a chart, for example. But as I mentioned earlier I started to look into this sort of query and I believe they can turn into something more compact as in a WHILE cycle. I'm aware of the old time If its not broken don't fix it so any input in the matter would be appretiated.

So far I'm stepping into something around these lines:

DECLARE @intYear INT
SET @intYear = 2013
WHILE (@intYear &lt; Year(GETDATE()))
BEGIN
    SELECT SUM(EmployeePaid)*2 AS CurrYear FROM TblRecords WHERE FYear = @intYear
    SET @intYear = @intYear + 1
END


Right now I'm stuck in trying to get the same output as the original query, since my WHILE its doing the trick but returning output for 3 different queries. I also cant manage to get CurrYear to "gain" a new value in each round, sort of like a CurrYear + @intYear kind of name.

Any hint is appreciated
Iterative approaches do have their place, but generally speaking it is much better to use set based approaches when working with databases.  I've heard that the math says that "set based solutions will be faster than iterative solutions in the vast majority of the cases" several times, but I can't seem to find a good reference at the moment.

If you really need to format it "like a chart" then you would pivot the data.  Here is the pivot:

SELECT 
    *
FROM 
(
    SELECT 
        [EmployeePaid] * 2 AS [EmployeePaid] -- Why 2x?
        , N'Total ' + CAST([FYear] AS NVARCHAR(4)) AS [Year] -- This output must match the 'IN' clause below
    FROM [TblRecords]
) as s
PIVOT
(
    SUM([EmployeePaid) -- Aggregate
    FOR [Year] IN ([Total 2013], [Total 2014], [Total 2015]) -- Match to pivoted columns
)as [pivot]


That gives you the output you wanted:

========================================
‖ Total 2013 ‖ Total 2014 ‖ Total 2015 ‖
========================================
‖ 42983.31   ‖ 76345.10   ‖  87233.5   ‖
========================================


Also in parting I would recommend trying for increased clarity instead of compacting your code.  While it is true the best line of code is the one you never write, the lines of code you do write must be maintainable.  That being said, PIVOT queries aren't the nicest to read because you're trying to get SQL Server to output data contrary to what it wants.  It might be worthwhile to have the application layer format the data instead.  Then your query would be as simple as:

SELECT
    [FYear]
    , SUM([EmployeePaid]) * 2 AS [YearTotal] -- Why 2x?
FROM [TblRecords]
WHERE
    [FYear] IN (2013, 2014, 2015)
GROUP BY
    [FYear]