Click here to Skip to main content
15,175,198 members
Home / Discussions / Database
   

Database

 
QuestionUPDATE Multiple tables on one filed. [modified] Pin
Member 808202113-Jul-11 12:12
MemberMember 808202113-Jul-11 12:12 
AnswerRe: UPDATE Multiple tables on one filed. Pin
Blue_Boy14-Jul-11 0:29
MemberBlue_Boy14-Jul-11 0:29 
AnswerRe: UPDATE Multiple tables on one filed. Pin
Shameel14-Jul-11 1:09
professionalShameel14-Jul-11 1:09 
AnswerRe: UPDATE Multiple tables on one filed. Pin
smcnulty200014-Jul-11 23:39
Membersmcnulty200014-Jul-11 23:39 
AnswerRe: UPDATE Multiple tables on one filed. [modified] Pin
Niladri_Biswas18-Jul-11 3:12
MemberNiladri_Biswas18-Jul-11 3:12 
QuestionCalculate and display a progressive balance Pin
Rameez Raja11-Jul-11 21:48
MemberRameez Raja11-Jul-11 21:48 
AnswerRe: Calculate and display a progressive balance Pin
Corporal Agarn12-Jul-11 5:40
professionalCorporal Agarn12-Jul-11 5:40 
AnswerRe: Calculate and display a progressive balance Pin
smcnulty200014-Jul-11 23:34
Membersmcnulty200014-Jul-11 23: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 23:49
MemberRameez Raja16-Jul-11 23:49 
GeneralRe: Calculate and display a progressive balance Pin
smcnulty200018-Jul-11 14:36
Membersmcnulty200018-Jul-11 14:36 
QuestionSelecting multiple columns from several tables without using JOIN Pin
Dominick Marciano11-Jul-11 5:41
professionalDominick Marciano11-Jul-11 5:41 
AnswerRe: Selecting multiple columns from several tables without using JOIN Pin
Blue_Boy11-Jul-11 5:55
MemberBlue_Boy11-Jul-11 5:55 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
David Mujica11-Jul-11 6:28
MemberDavid Mujica11-Jul-11 6:28 
AnswerRe: Selecting multiple columns from several tables without using JOIN Pin
kmoorevs11-Jul-11 11:08
Memberkmoorevs11-Jul-11 11:08 
AnswerRe: Selecting multiple columns from several tables without using JOIN Pin
Shameel11-Jul-11 22:30
professionalShameel11-Jul-11 22:30 
AnswerRe: Selecting multiple columns from several tables without using JOIN Pin
David Skelly12-Jul-11 4:54
MemberDavid Skelly12-Jul-11 4:54 
AnswerRe: Selecting multiple columns from several tables without using JOIN Pin
AnnieMacD14-Jul-11 7:24
MemberAnnieMacD14-Jul-11 7:24 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
Shameel14-Jul-11 19:52
professionalShameel14-Jul-11 19:52 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
smcnulty200014-Jul-11 23:46
Membersmcnulty200014-Jul-11 23:46 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
Shameel15-Jul-11 3:22
professionalShameel15-Jul-11 3:22 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
AnnieMacD15-Jul-11 3:45
MemberAnnieMacD15-Jul-11 3:45 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
Shameel15-Jul-11 8:50
professionalShameel15-Jul-11 8:50 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
AnnieMacD15-Jul-11 8:56
MemberAnnieMacD15-Jul-11 8:56 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
smcnulty200015-Jul-11 6:39
Membersmcnulty200015-Jul-11 6:39 
GeneralRe: Selecting multiple columns from several tables without using JOIN Pin
Shameel15-Jul-11 8:48
professionalShameel15-Jul-11 8:48 

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.