Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 can anyone help me in my problem in database?

Author  Topic 

haekz008
Starting Member

10 Posts

Posted - 2012-01-24 : 03:55:24
i am searching for a query that can add the value of the two attributes,.,for example, i have a 3 attributes which is the total payment, partial payment and last payment,.,

how am i going to get the value of the partial and last payment and insert it on the total payment?

help me pls,.,
thankyou

haekz008

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2012-01-24 : 04:33:35
Read about "Compute Column" in Books online..

Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-24 : 04:50:52
quote:
Originally posted by senthil_nagore

Read about "Computed Column" in Books online..

Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008




No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-24 : 05:04:20
Not sure if that actually fits your requirement.

Did you mean that you need to calculate some sort of running total from each row to the next? If so post some sample data and the required output.


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

haekz008
Starting Member

10 Posts

Posted - 2012-01-24 : 05:19:50
At charlie
-->

here is the example

partial payment-----Last payment------total payment

-------5-----------------5------------------10


by the way thanks for the help of others,.,



haekz008
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-24 : 05:47:00
if you already have partial payment and last payment in the table then all you need is a computed column (as the others said)

Something like

BEGIN TRAN

CREATE TABLE #foo (
[val1] INT
, [val2] INT
)

ALTER TABLE #foo ADD [computedCol1] AS [val1] + [val2] PERSISTED

INSERT #foo ([val1], [val2])
VALUES (1,1), (1,2), (2,2)

SELECT * FROM #foo

ROLLBACK

Results:


val1 val2 computedCol1
----------- ----------- ------------
1 1 2
1 2 3
2 2 4


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

haekz008
Starting Member

10 Posts

Posted - 2012-01-24 : 06:20:18
thank yo very much for your help,.,it really helps :)


haekz008
Go to Top of Page
   

- Advertisement -