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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 minus

Author  Topic 

adeline
Starting Member

7 Posts

Posted - 2006-04-12 : 10:44:46
is there a minus function for sql query?
sum(table1) - sum(table2)

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-12 : 10:49:18
What do you mean by sum(table1) - sum(table2)?
Give more details

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2006-04-12 : 11:15:21
Sure:
select (select sum(...) from table1)-(select sum(...) from table2)
Go to Top of Page

adeline
Starting Member

7 Posts

Posted - 2006-04-12 : 11:45:36
i mean, calculate the table1(total) and minus it from table2(total).
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-12 : 11:55:16
Use the method suggested by mmarovic, or post some sample and expected data

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

adeline
Starting Member

7 Posts

Posted - 2006-04-12 : 11:55:20
got error for tht query .... :(
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-12 : 11:56:53
quote:
Originally posted by adeline

got error for tht query .... :(


What is the error?
Post the query you used

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

adeline
Starting Member

7 Posts

Posted - 2006-04-12 : 11:57:01
select ( select sum(inc_amo) from inc)-(select sum(nec_amo) from nec)
Go to Top of Page

adeline
Starting Member

7 Posts

Posted - 2006-04-12 : 11:59:17

im using a pocket pc emulator, so i cant copy and paste the error. but it is written: error in command
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-04-12 : 17:44:36
This is syntax is not supported in SQL CE. You have to do it in 3 steps using your application
Step 1 : find the sum of table1
Step 2 : find the sum of table2
Setp 3 : subtract it



KH


Go to Top of Page

adeline
Starting Member

7 Posts

Posted - 2006-04-13 : 02:32:27
how to use the subtract ? i can find the total for sum1 and sum2.

'Create a connection to the new database
Dim ssceconn As New SqlCeConnection("Data Source = \My Documents\ppc.sdf")

'Initialize DataSet
dstotaln = New DataSet
dstotali = New DataSet

'data adaptor that will fills the dataset
datotaln = New SqlCeDataAdapter("select sum(nec_amo)AS totaln from nec ", ssceconn)
datotali = New SqlCeDataAdapter("select sum(inc_amo)AS totali from inc ", ssceconn)

'fills dataset with only results from string
datotaln.Fill(dstotaln, "nec")
datotali.Fill(dstotali, "inc")

textBalance.DataBindings.Add("Text", dstotaln.Tables("nec"), "totaln")

TextBox1.DataBindings.Add("Text", dstotaln.Tables("nec"), "totaln")
TextBox2.DataBindings.Add("Text", dstotali.Tables("inc"), "totali")
Go to Top of Page
   

- Advertisement -