grogo21
asked on
Sql Syntax
Hello, I was wondering how I can modify the sql query I have below so that instead of setting @StatCode manully each time It would select all of the StatCodes in a table and complete the operation below for each one.
The table and field which contains the StatCode values is StatSource.StatCode.
Thanks!
The table and field which contains the StatCode values is StatSource.StatCode.
Thanks!
Declare @StatCode int
Set @StatCode = 8
select (select COUNT(Distinct(VisitorID))+.0
from OutboundTraffic
where VisitorID in(select VisitorID
from InboundTraffic
where StatCode = @StatCode))/(select COUNT(*) from Stats where StatCode = @StatCode)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry Angel, didn't see your post until just now.
ASKER
mwvisa1: I got error:
Column 'InboundTraffic.StatCode' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
angelllll
what if (select COUNT(*) from Stats where stats.StatCode = s.StatCode) as perc = 0?
Thanks!
Column 'InboundTraffic.StatCode' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
angelllll
what if (select COUNT(*) from Stats where stats.StatCode = s.StatCode) as perc = 0?
Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I still get a divide by zero error.
Thanks!
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And you can change my alias StatCount to be StatPercent or something more appropriate.
ASKER
Thanks Everyone!
Open in new window