Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SELECT Count Current Year From Q-String

Author  Topic 

brmcdani44
Starting Member

4 Posts

Posted - 2011-10-26 : 09:54:39
I am trying to select a count of all records that fall in the year of a querystring passed in the web browser. Only trouble is I keep getting the same COUNT as when I select all records between the two dates in the query string. Anyone have an idea on what I am doing wrong here? Thanks in advance.



(SELECT COUNT(*) WHERE type_desc='XXXXX' AND year(incident.inc_datetime) = YEAR(@BegDate)) AS XXXXXCurrentYearCount

Sachin.Nand

2937 Posts

Posted - 2011-10-26 : 11:09:29
Where in the ACTUAL date filter in the query ?

PBUH

Go to Top of Page

brmcdani44
Starting Member

4 Posts

Posted - 2011-10-26 : 11:37:54
[code]SELECT incident.inc_no,

(SELECT COUNT(*) WHERE type_desc='X') AS XMonthCount,

(SELECT COUNT(*) WHERE type_desc='X' AND incident.inc_datetime Between @BegDate AND @EndDate AND (ucr_code='09A' OR ucr_code='09B' OR ucr_code='09C' AND incident.status <> 'Active' )) AS XMonthCleared,

(SELECT COUNT(*) WHERE type_desc='X' AND year(incident.inc_datetime) = YEAR(@BegDate)) AS XCurrentYearCount,

(SELECT COUNT(*) WHERE type_desc='X' AND year(incident.inc_datetime) = YEAR(@BegDate) AND (ucr_code='09A' OR ucr_code='09B' OR ucr_code='09C' AND incident.status <> 'Active' )) AS XCurrentYearClearedCount

FROM incident
WHERE incident.inc_datetime Between @BegDate AND @EndDate
[/code]
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2011-10-26 : 12:26:18
quote:
Originally posted by brmcdani44

SELECT incident.inc_no,

(SELECT COUNT(*) WHERE type_desc='X') AS XMonthCount,

(SELECT COUNT(*) WHERE type_desc='X' AND incident.inc_datetime Between @BegDate AND @EndDate AND (ucr_code='09A' OR ucr_code='09B' OR ucr_code='09C' AND incident.status <> 'Active' )) AS XMonthCleared,

(SELECT COUNT(*) WHERE type_desc='X' AND year(incident.inc_datetime) = YEAR(@BegDate)) AS XCurrentYearCount,

(SELECT COUNT(*) WHERE type_desc='X' AND year(incident.inc_datetime) = YEAR(@BegDate) AND (ucr_code='09A' OR ucr_code='09B' OR ucr_code='09C' AND incident.status <> 'Active' )) AS XCurrentYearClearedCount

FROM incident
WHERE incident.inc_datetime Between @BegDate AND @EndDate




Where is table name in the inner queries ???

(SELECT COUNT(*)No tablename here WHERE type_desc='X') AS XMonthCount


PBUH

Go to Top of Page
   

- Advertisement -