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.
| Author |
Topic |
|
ndn_24_7
Starting Member
23 Posts |
Posted - 2005-01-26 : 14:42:14
|
| Hello all,I'm trying to write a stored procedure that will prompt the user for adate range and produce a report based on that date range and 4 incidenttypes. I only need count how may times these incidents happen withinthe data range. The query looks like thisSELECT incident, @Enter_Beginning_Date AS [Beginning Date],@Enter_Ending_Date AS [Ending Date], COUNT(*) AS OccurancesFROM dbo.IncidentWHERE (DateOccured BETWEEN @Enter_Beginning_Date AND@Enter_Ending_Date) AND (incident = 'Customer Accident')GROUP BY incidentThis works fine, but I need to get incident = customer accident,Customer Illness, Employee Accident and Employee Illness in my incidenttable. When ever I try to add Incident = Customer Illness to thisquery, I get no results. Any assistance will be greatly appreciated.The table I'm trying to query looks something like thisID(int) Incident(nvarchar) DateOccured (datetime)1200 Customer Illness 1/1/20031201 Customer Illness 1/2/20031202 Customer Accident 1/2/20031203 Customer Accident 1/3/20031204 Employee Accident 1/5/20031205 Employee Illness 1/6/2003The stored procedure prompts the user for a beginning(@Enter_Beginning_Date) and ending date(@Enter_Ending_Date) which usesthe DateOccured column for the specified date range. I want the queryto count the number of occurences that happen within the specified daterange. I want to create a report that looks loke thisIncident Number of OccurencesCustomer Illness 2Customer Accident 2Employee Accident 1Employee Illness 1When ever I query for one incident (Customer Accident), the query willwork fine, but when I insert another statement [(incident = CustomerIllness) AND (incident = Customer Accident)] I get no results, when Iknow there are at least 3 incidents of Customer Illness. Does this help? |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-01-26 : 15:22:02
|
| I think you need to change your AND to an OR:[(incident = Customer Illness) AND (incident = Customer Accident)] |
 |
|
|
|
|
|