|
Thread: SQL
-
Sep 7th, 2000, 06:39 AM
#1
Thread Starter
Hyperactive Member
I want to calculate the sum of "price" in a orders table into a variable....
I tried this..
sSql = "select sum(price) into intPrice from orders where client = 007"
This does not work.
Can anyone please help!!??
-
Sep 7th, 2000, 07:55 AM
#2
Addicted Member
Hi
I'm quite new to SQL and VB but could you try this:
sSQL= "SELECT Sum(price) FROM Orders WHERE Client = '" & 007 & "' "
Set rsSUM = ConnectionObject.Execute( sSQL )
rsSUM.MoveFirst
SumTotal =rsSUM( "price" )
ssSQL= "INSERT INTO intPrice FieldName Values '" & SumTotal & "'
Set rsInsert = ConnectionObject.Execute( ssSQL )
Its probably bullshit, but I'm trying something similar at the moment and this seems like should work to me, No promisses though.
In abit 'G'
Skeen
"It wasn't the booze that made me snooze, It was the Gin that did me in!"
-
Sep 7th, 2000, 09:02 AM
#3
Lively Member
Are you wanting to contain this SQL all within the DB environment or are you asigning the result to a VB var?
If the former then the following works for SQL Server...
DECLARE @mySum as DECIMAL (12)
SELECT @mySum =
(SELECT sum(price) FROM orders WHERE blah = blah)
Anakim
It's a small world but I wouldn't like to paint it.
-
Sep 7th, 2000, 09:57 AM
#4
Thread Starter
Hyperactive Member
Anakim,
I want to assign the result to a VB variable!!
I'm ripping my hair out on this side!!
-
Sep 7th, 2000, 11:23 AM
#5
Frenzied Member
this shold work
Code:
dim TotalPrice as Currency
SQL ="SELECT SUM(price)as SumOfPrice FROM Orders WHERE client = 007"
rs.open sql, db
TotalPrice = rs!SumOfPrice
that should work
samething as yours, you were just missing "as"
-
Sep 7th, 2000, 12:18 PM
#6
Thread Starter
Hyperactive Member
Thanks kovan,
This works 100%
-
Sep 7th, 2000, 01:49 PM
#7
Frenzied Member
welcome
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|