Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: SV: Re: Count WHERE...howto?


Message #1 by "SD-Studios" <info@s...> on Sat, 10 Nov 2001 17:39:30 +0100
Ahhhh! =) Okay! Thanks, pal!

--

Martin Johansson





-----Ursprungligt meddelande-----

Fran: Imar Spaanjaars [mailto:Imar@S...]

Skickat: den 10 november 2001 16:52

Till: ASP Databases

Amne: [asp_databases] Re: Count WHERE...howto?





You can use Count(*) or Count(ID) where ID is the unique ID for your table.



Beware for unexpected results: Count(*) includes null values, where as

Count(columnName) only returns non-null values.



In the above example, if ID is the primary key for the table, there

wouldn't be a difference between Count(*) and Count(ID) as there shouldn't

be any NULL values in the ID column.



Hope this helps,



Imar





At 04:49 PM 11/10/2001 +0100, you wrote:

>If I have a field in a table that is called genre. Now I want to count how

>many games that is in each genre.

>How do I count this? Do I do it like e.g. SELECT Count(genre) FROM mytable

>WHERE genre = '" & Request.QueryString("genre") & "'? Or how do I count?

>--

>Martin Johansson

>

>

>



















Message #2 by "SD-Studios" <info@s...> on Sat, 10 Nov 2001 17:51:54 +0100
Do i print this out like objRS("Count(*)") or something??

--

Martin Johansson





-----Ursprungligt meddelande-----

Fran: Imar Spaanjaars [mailto:Imar@S...]

Skickat: den 10 november 2001 16:52

Till: ASP Databases

Amne: [asp_databases] Re: Count WHERE...howto?





You can use Count(*) or Count(ID) where ID is the unique ID for your table.



Beware for unexpected results: Count(*) includes null values, where as

Count(columnName) only returns non-null values.



In the above example, if ID is the primary key for the table, there

wouldn't be a difference between Count(*) and Count(ID) as there shouldn't

be any NULL values in the ID column.



Hope this helps,



Imar





At 04:49 PM 11/10/2001 +0100, you wrote:

>If I have a field in a table that is called genre. Now I want to count how

>many games that is in each genre.

>How do I count this? Do I do it like e.g. SELECT Count(genre) FROM mytable

>WHERE genre = '" & Request.QueryString("genre") & "'? Or how do I count?

>--

>Martin Johansson

>

>

>



















Message #3 by "SD-Studios" <info@s...> on Sat, 10 Nov 2001 17:56:02 +0100
"SELECT Count(*) FROM games WHERE genre = '" & aa & "'"



With this SQL-string I get:

ADODB.Recordset error '800a0cc1'

Item cannot be found in the collection corresponding to the requested name

or ordinal.



And I know there is records where genre = aa

How should I do?

--

Martin Johansson





-----Ursprungligt meddelande-----

Fran: Imar Spaanjaars [mailto:Imar@S...]

Skickat: den 10 november 2001 16:52

Till: ASP Databases

Amne: [asp_databases] Re: Count WHERE...howto?





You can use Count(*) or Count(ID) where ID is the unique ID for your table.



Beware for unexpected results: Count(*) includes null values, where as

Count(columnName) only returns non-null values.



In the above example, if ID is the primary key for the table, there

wouldn't be a difference between Count(*) and Count(ID) as there shouldn't

be any NULL values in the ID column.



Hope this helps,



Imar





At 04:49 PM 11/10/2001 +0100, you wrote:

>If I have a field in a table that is called genre. Now I want to count how

>many games that is in each genre.

>How do I count this? Do I do it like e.g. SELECT Count(genre) FROM mytable

>WHERE genre = '" & Request.QueryString("genre") & "'? Or how do I count?

>--

>Martin Johansson

>

>

>



















Message #4 by Imar Spaanjaars <Imar@S...> on Sat, 10 Nov 2001 17:56:04 +0100
No, you could alias your count and refer to it like a normal column in a 

normal SQL statement



sSQL = "Select Count(field1) as NumberOfRecords WHERE etc etc"

' Get recordset with sSQL



Then you can either use this:



objRS("NumberOfRecords") or



objRS(0)



IMO, the first is more readable.



Imar









At 05:51 PM 11/10/2001 +0100, you wrote:

>Do i print this out like objRS("Count(*)") or something??

>--

>Martin Johansson

>

>

>-----Ursprungligt meddelande-----

>Fran: Imar Spaanjaars [mailto:Imar@S...]

>Skickat: den 10 november 2001 16:52

>Till: ASP Databases

>Amne: [asp_databases] Re: Count WHERE...howto?

>

>

>You can use Count(*) or Count(ID) where ID is the unique ID for your table.

>

>Beware for unexpected results: Count(*) includes null values, where as

>Count(columnName) only returns non-null values.

>

>In the above example, if ID is the primary key for the table, there

>wouldn't be a difference between Count(*) and Count(ID) as there shouldn't

>be any NULL values in the ID column.

>

>Hope this helps,

>

>Imar

>

>

>At 04:49 PM 11/10/2001 +0100, you wrote:

> >If I have a field in a table that is called genre. Now I want to count how

> >many games that is in each genre.

> >How do I count this? Do I do it like e.g. SELECT Count(genre) FROM mytable

> >WHERE genre = '" & Request.QueryString("genre") & "'? Or how do I count?

> >--

> >Martin Johansson

> >

> >

> >




>

>

>

>




>

>

>

>









  Return to Index