November 26, 2012 at 12:41 am
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
November 26, 2012 at 12:55 am
can you explain a bit ? i am not clear as if you are adding or subtracting columns value :hehe:
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
November 26, 2012 at 1:31 am
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
November 26, 2012 at 2:23 am
kiasystemsoft (11/26/2012)
SorryI 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----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
November 26, 2012 at 3:00 am
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
Link to my Blog Post --> www.SQLPathy.com[/url]
Follow me @Twitter
November 26, 2012 at 3:40 am
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
November 26, 2012 at 3:58 am
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
November 26, 2012 at 4:10 am
of Declare @where use for create Condition on table
November 26, 2012 at 5:50 am
I do not have information to help
November 26, 2012 at 10:39 pm
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----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply