SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SELECT Count Current Year From Q-String
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

brmcdani44
Starting Member

4 Posts

Posted - 10/26/2011 :  09:54:39  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

2937 Posts

Posted - 10/26/2011 :  11:09:29  Show Profile  Reply with Quote
Where in the ACTUAL date filter in the query ?

PBUH

Go to Top of Page

brmcdani44
Starting Member

4 Posts

Posted - 10/26/2011 :  11:37:54  Show Profile  Reply with Quote
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       
Go to Top of Page

Sachin.Nand
Flowing Fount of Yak Knowledge

2937 Posts

Posted - 10/26/2011 :  12:26:18  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000