tags:

views:

32

answers:

1

Hi

I am using mssql and I want to make a query that returns a count back with a where clause.

Like say I have a product Table

ProductId
ProductName
Active

So how would I make it

I have like

Select Count(*)
From Product

now I don't know how to filter it so it only could if Active = true;

So if there are 3 active products then it would return a count of 3 even if there is a hundred rows in the db and the other 97 are only not active.

so the where clause would be probably like

where active = true

I am not sure how to put them together though.

+3  A: 

You are there..just use:

Select Count(*)
From Product
where active = 'true'

Assuming your active field is of varchar or something similar.

codaddict
Your where clause might have to be `where active = 1`, depending on the schema.
Jonathan Julian
Yep your right it has to be 1. I thought I could use true.
chobo2
i bet you can use true as long as you don't quote it:where active = true
Leslie