Click here to Skip to main content
15,898,134 members
Home / Discussions / Database
   

Database

 
GeneralRe: Dynamic Query Question Pin
Kevin Marois15-Jul-11 5:34
professionalKevin Marois15-Jul-11 5:34 
GeneralRe: Dynamic Query Question Pin
smcnulty200015-Jul-11 22:31
smcnulty200015-Jul-11 22:31 
AnswerRe: Dynamic Query Question Pin
smcnulty200014-Jul-11 21:53
smcnulty200014-Jul-11 21:53 
AnswerRe: Dynamic Query Question Pin
dasblinkenlight15-Jul-11 17:00
dasblinkenlight15-Jul-11 17:00 
AnswerRe: Dynamic Query Question Pin
PIEBALDconsult16-Jul-11 4:27
mvePIEBALDconsult16-Jul-11 4:27 
JokeRe: Dynamic Query Question Pin
Mycroft Holmes16-Jul-11 13:06
professionalMycroft Holmes16-Jul-11 13:06 
GeneralRe: Dynamic Query Question Pin
S Douglas11-Aug-11 9:48
professionalS Douglas11-Aug-11 9:48 
GeneralRe: Dynamic Query Question Pin
PIEBALDconsult11-Aug-11 14:49
mvePIEBALDconsult11-Aug-11 14:49 
GeneralRe: Dynamic Query Question Pin
S Douglas12-Aug-11 4:48
professionalS Douglas12-Aug-11 4:48 
GeneralRe: Dynamic Query Question Pin
PIEBALDconsult12-Aug-11 17:57
mvePIEBALDconsult12-Aug-11 17:57 
GeneralRe: Dynamic Query Question Pin
S Douglas13-Aug-11 8:20
professionalS Douglas13-Aug-11 8:20 
GeneralRe: Dynamic Query Question Pin
PIEBALDconsult13-Aug-11 9:29
mvePIEBALDconsult13-Aug-11 9:29 
GeneralRe: Dynamic Query Question Pin
S Douglas13-Aug-11 22:30
professionalS Douglas13-Aug-11 22:30 
GeneralRe: Dynamic Query Question Pin
PIEBALDconsult13-Aug-11 7:15
mvePIEBALDconsult13-Aug-11 7:15 
QuestionUPDATE Multiple tables on one filed. [modified] Pin
Member 808202113-Jul-11 11:12
Member 808202113-Jul-11 11:12 
AnswerRe: UPDATE Multiple tables on one filed. Pin
Blue_Boy13-Jul-11 23:29
Blue_Boy13-Jul-11 23:29 
AnswerRe: UPDATE Multiple tables on one filed. Pin
Shameel14-Jul-11 0:09
professionalShameel14-Jul-11 0:09 
AnswerRe: UPDATE Multiple tables on one filed. Pin
smcnulty200014-Jul-11 22:39
smcnulty200014-Jul-11 22:39 
AnswerRe: UPDATE Multiple tables on one filed. [modified] Pin
Niladri_Biswas18-Jul-11 2:12
Niladri_Biswas18-Jul-11 2:12 
QuestionCalculate and display a progressive balance Pin
Rameez Raja11-Jul-11 20:48
Rameez Raja11-Jul-11 20:48 
AnswerRe: Calculate and display a progressive balance Pin
Corporal Agarn12-Jul-11 4:40
professionalCorporal Agarn12-Jul-11 4:40 
AnswerRe: Calculate and display a progressive balance Pin
smcnulty200014-Jul-11 22:34
smcnulty200014-Jul-11 22:34 
One way to do this is with a subquery.

I assume an element number which is an int, that is numbered according to how you want to display this. However this is more sensible if you actually have dates and do the subquery comparison based on the date. Element also could be your customer order id (or invoice id, or whatever) if those are sequential.

SELECT [Element]
,[Amount]
,(select SUM(Amount) from AmountTabletb where tb.Element<=ta.Element )
NewBalance
FROM [yourdatabase].[dbo].[AmountTable] ta

And then adding in the original balance with another subquery.

SELECT [Element]
,[Amount]
,(select SUM(Amount) from AmountTabletb where tb.Element <= ta.Element )
+ (select top 1 balance from AmountTable tb where tb.Element=1 ) NewBalance
FROM [yourdatabase].[dbo].[AmountTable] ta

Remember; your subquery can return only a single value per row or you get an error so always use a 'top 1' clause or a summary function like SUM() or Max().
_____________________________
Give a man a mug, he drinks for a day. Teach a man to mug...

GeneralRe: Calculate and display a progressive balance Pin
Rameez Raja16-Jul-11 22:49
Rameez Raja16-Jul-11 22:49 
GeneralRe: Calculate and display a progressive balance Pin
smcnulty200018-Jul-11 13:36
smcnulty200018-Jul-11 13:36 
QuestionSelecting multiple columns from several tables without using JOIN Pin
Dominick Marciano11-Jul-11 4:41
professionalDominick Marciano11-Jul-11 4:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.