Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL help!!! ...working in code

Status
Not open for further replies.

jammerdk

Technical User
Aug 16, 2001
51
DK
Hi I'm trying to figure out how to calculate certain fields in SQL but I'm running against problems everytime got it working in code on a single form but I want it to in a continuous form.

the form is based on a query Counting ID and Grouped by Type

my code looks something like this

Me.TotalSum = DCount("ID", "tblUnimec", "Type='" & Cbotype & "'")
Me.Sum1 = DCount("[Good]", "tblUnimec", "[Good] = 1 And type='" & Cbotype & "'")
Me.Sum2 = DCount("[Good]", "tblUnimec", "[Good] = 2 And type='" & Cbotype & "'")
Me.Pro1 = (100 / Me.TotalSum) * Me.Sum1 & " %"
Me.Pro2 = (100 / Me.TotalSum) * Me.Sum2 & " %"

Hope some of u guys could help me on transforming it to SQL

 
If it helps, the easiest SQL equivalent of a DCount like this

DCount("ID", "tblUnimec", "Type='" & Cbotype & "'")


Is this

"SELECT Count(*) FROM tblUnimec WHERE Type='" & Cbotype & "';"
 
Tried what u described only got a field containing Expr..and no data
 
And what about a query like this (SQL code) ?
SELECT ID, type, Count(*) AS TotalSum
, Sum(IIf([Good]=1,1,0)) As Sum1
, Sum(IIf([Good]=2,1,0)) As Sum2
, Sum(IIf([Good]=1,1,0))*(Count(*)/100) As Pro1
, Sum(IIf([Good]=2,1,0))*(Count(*)/100) As Pro2
FROM tblUnimec
GROUP BY ID, type

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
thanx PHV just what I needed to get further into SQL ...solved it now.

Ps. have a star
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top