Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQLServer 2008 code 1

Status
Not open for further replies.

landview

Programmer
Mar 19, 2013
4
US
I have a table like:
MonthOpened #ofDefectOpened MonthClosed #ofDefectClosed Oustanding
Jan 2013 50 Jan 2013 30
Feb 2013 20 Feb 2013 30
Mar 2013 60 Feb 2013 20

I need to calculate the outstanding and create the view.
Calculation for outstanding: For Jan 2013 Outstanding=#ofDefectOpened - #ofDefectClosed=50-30=20
For Feb 2013 Outstanding=Jan 2013 Outstanding+Feb 2013 #ofDefectOpened- Mar 2013#ofDefectClosed =20+20-30=10
For Mar 2013 Outstanding=Feb 2013 Outstanding+Mar 2013 #ofDefectOpened- Mar 2013#ofDefectClosed =10+60-20=50

Please let me know how to do this in Sql Sever 2008.
Thank you
 
select monthopened,#ofdefectopened,monthclosed,#ofdefectclosed,,(#ofdefectopened-#ofdefectclosed) as outstanding from the table;

but, I am unable to keep on adding the Previous month outstanding to the next month. Couldn't figure out. If you know please let me know.
Thank you.
 
Instead of giving you a direct solution I am pointing you out to what you need to search for.

What you have a a running total - so search both here on tek-tips and on google for "sql server 2008 running total" and you will find lots of examples with different ways of doing it.

As you will get different ways of doing it it will be a learning step for you

Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top