A: 

Firstly, can you try simplifying your SQL to:

SELECT count(*)
  FROM history h
 WHERE h.period = '0:00:15'
       AND h.request = '1'
       AND h.stepped = '1'
       AND h.ts BETWEEN StartTime AND EndTime
       AND (   (h.name = Tag1Name AND h.value = Tag1Cond) 
            OR (h.name = Tag2Name AND h.value = Tag2Cond));

Other than that, I can't see why you wouldn't get values for two dates in the same month -- unless your data only contained monthly entries, which I'm guessing isn't the case.

Could you post some sample data from the history table?

Tom
I just added some.
tigerfan2010
I think I want to add some kind of join statement or something to the code. I your code for the last hour. So I want the code to count the number of times when the running tag is 1 and the product is 13. That should be 240 times. A tag for every 15 secs for an hour. Your code output 480 so it count up both of them. I want to know how to compare the two tables. I appreciate the help I don't think I was clear enough on what I want I am trying to do.
tigerfan2010
I was able to modify your code slightly and get it to work. Thanks for the help.
tigerfan2010