Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to show variance in column values

Author  Topic 

vignesht50
Yak Posting Veteran

82 Posts

Posted - 2014-02-19 : 09:29:35
Hi,

This is my table structure
--=====
create table calculate(
ID int identity (1,1),
PreviousYear_Profit float not null,
)

insert into calculate values (12500)
insert into calculate values (22700)
insert into calculate values (18500)
insert into calculate values (25800)
--======

I want to calculate variance and expected output is

ID PreviousYear PriorVersion Variance
1 12500 sum(PreviousYear) PreviousYear-PriorVersion
2 22700 sum(PreviousYear) PreviousYear-PriorVersion
3 18500 sum(PreviousYear) PreviousYear-PriorVersion
4 25800 sum(PreviousYear) PreviousYear-PriorVersion

I don't have PriorVersion and Variance columns.
PriorVersion will be like sum(PreviousYear)
Variance will be (PreviousYear - PriorVersion)

I can query if I have column, since I don't have these two column how could I possibly achieve the output using my existing table schema. Can anyone assist me in this.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-20 : 00:26:26
if you dont have those columns how do you get values for it? does it come from user input or another table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -