I am really trying to understand using array's. this works, now i am
"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
news:eOxK6nCVGHA.6048@TK2MSFTNGP11.phx.gbl...
> Do both the count and the sum in the same statement:
>
> sql=select sum(wins1) as wins_8, " & _
> "count(*) as totalwins from matches_8ball " & _
> "where username = ?"
> arparm=array(var)
> set cmd=createobject("adodb.command")
> cmd.commandtext=sql
> cmd.commandtype=1
> set cmd.activeconnection=conn
> set wins8 = cmd.execute(,arparm)
> wins__8=0
> if wins8(1) > 0 then wins__8=wins8(0)
> wins8.close:set wins8=nothing
>
> HTH,
> Bob Barrows
>
>
> Jeff wrote:
>> i am using Access DB, and I already tried that.
>> I am getting it to work, just takes extra work.
>> i am getting a count(username) first, then if the count is > 0
>> process it, if not, then the var = 0
>>
>> it is working that way, but i am still looking for an easier way to
>> do it.
>>
>>
>> "Mark J. McGinty" <mmcginty@spamfromyou.com> wrote in message
>> news:u5fdDKCVGHA.1160@TK2MSFTNGP09.phx.gbl...
>>>
>>> "Jeff" <gig_bam@adelphia.net> wrote in message
>>> news:INidnWF8rZ4_j7HZnZ2dneKdnZydnZ2d@adelphia.com...
>>>> In my asp script, i am using sql to get a sum. I understand if the
>>>> row doesn't contain a value, it is skipped. But the problem i am
>>>> running into is if there isn't a row that meets the criteria at all.
>>>>
>>>> i have this
>>>>
>>>> set wins8 = conn.execute("select sum(wins1) as wins_8 from
>>>> matches_8ball where username = '" & var & "'")
>>>> if not wins8.eof then
>>>> wins__8 = wins8.fields.item("wins_8").value
>>>> else
>>>> wins__8 = 0
>>>> end if
>>>>
>>>> i thought that if it didn't find the '" & var & "' at all in the
>>>> username column, it should return a 0 value. but this isn't working
>>>> as you can see here.
>>>>
>>>>
http://pool.gig-gamers.com/all_stats2.asp >>>>
>>>> and since that isn't working, or any of the others like it, the
>>>> table contains blank spaces.
>>>> any ideas??
>>>>
>>>> i guess i am trying to see if there is a way to maybe say... if
>>>> wins__8 = Nul or something
>>>
>>> What db engine are you using? If SQL Server, try:
>>>
>>> select coalesce(sum(wins1), 0) as wins_8 from matches_8ball ...
>>>
>>> Also consider parameterizing that query, by using a command object,
>>> rather than dynamic SQL, which risks a SQL injection attack.
>>>
>>>
>>> -Mark
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>