|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Sunday, November 25, 2012 11:37 PM
Points: 9,
Visits: 0
|
|
I have two columns. Name column 1 is F1 Name column 2 is F2
I would calculate two columns And the third field to be shown
For example : F1 20000 0 55000 0 0 11000
F2 0 5000 0 60000 20000 0
F3 20000 15000 70000 -10000 -30000 -19000
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 7:03 AM
Points: 2,562,
Visits: 3,453
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Sunday, November 25, 2012 11:37 PM
Points: 9,
Visits: 0
|
|
Sorry I can not speek English well
I have two fields
The account is a person
In each row I have a previous account
It may be that the debtor or creditor
If you do not understand the explanation again
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 7:03 AM
Points: 2,562,
Visits: 3,453
|
|
kiasystemsoft (11/26/2012) Sorry I can not speek English well
I have two fields
The account is a person
In each row I have a previous account
It may be that the debtor or creditor
If you do not understand the explanation again thats not a problem unless you made the requirement or problem celar here . please send any examole that when amount wil get added or subtracted ?
-------Bhuvnesh---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 10:16 PM
Points: 1,227,
Visits: 1,356
|
|
If this is a simple debit/credit problem, here is one of the way to solve. I have tried creating a sample table called "Account".
create table Account(id int identity, F1 int, F2 int,F3 int)
insert into Account(F1,F2) values (20000,0), (0,5000), (55000,0), (0,60000), (0,20000), (11000,0)
select id,F1,F2,(select SUM(F1-f2) from Account where id <=a.id) F3 from Account a
~ Lokesh Vij
Guidelines for quicker answers on T-SQL question Guidelines for answers on Performance questions
Link to my Blog Post --> www.SQLPathy.com
Follow me @Twitter

|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Sunday, November 25, 2012 11:37 PM
Points: 9,
Visits: 0
|
|
Thank you for your answer... But my issue is not resolved Because of this sort must be based on the Id field
I used the following method
SET @SQLStr ='DECLARE @F3 bigint=0 update viwe1 set @f3=f3=@f3+ (f1-f2), f5 = case when @f3<0 then ''c'' when @f3>0 then "b" when @f3=0 then "a" end '+ @where
EXEC(@SQLStr);
But sometimes makes mistakes It is right on the main table But the mistaken view
|
|
|
|
|
SSCarpal Tunnel
       
Group: General Forum Members
Last Login: Tuesday, June 04, 2013 7:03 AM
Points: 4,443,
Visits: 7,249
|
|
That will always make mistakes since you haven't declared @where.
To solve your problem, please search this site for "running totals". You should be able to find something that you can adapt to your situation.
If there's anything you don't understand after that, please post back with table DDL, sample data in the form of INSERT statements, and expected results.
John
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Sunday, November 25, 2012 11:37 PM
Points: 9,
Visits: 0
|
|
| of Declare @where use for create Condition on table
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Sunday, November 25, 2012 11:37 PM
Points: 9,
Visits: 0
|
|
| I do not have information to help
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 7:03 AM
Points: 2,562,
Visits: 3,453
|
|
kiasystemsoft (11/26/2012) I do not have information to help we dont require any info from your side , just follow what John Mitchell-245523 explained above. and take help from any person who can make you understand all above stuff (from english perspective)
-------Bhuvnesh---------- While 1 = 1 (Learning SQL....) Click to get fast response of your post
|
|
|
|