Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Get 2 column result from 1 field Expand / Collapse
Author
Message
Posted Friday, June 14, 2013 4:38 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, December 24, 2013 4:56 AM
Points: 178, Visits: 668
:)

\m/ O_o \m/

Thnaks!
Post #1463471
Posted Friday, June 14, 2013 1:13 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, October 9, 2014 6:37 AM
Points: 147, Visits: 85
Another approach using CTEs

create table #Table1
(
Years int,
[Value] int
)

insert #Table1(Years, [Value])
Values
(2000, 2)
,(2001, 4)
,(2002, 5)
,(2003, 3)
,(2004, 2)
GO
with SumAll(FullTotal) AS
(SELECT SUM([value]) FROM #Table1)
,SumPartial(PartialTotal) AS
(SELECT SUM([Value]) FROM #Table1 WHERE Years <= 2002)
SELECT a.FullTotal, b.PartialTotal
FROM SumALL a, SumPartial b

Post #1463754
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse