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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 close on query but can't quite get it

Author  Topic 

Pr0FiT
Starting Member

7 Posts

Posted - 2010-09-22 : 11:49:59
I've been tasked w/ helping our report team figure out a query. I'm no sql expert myself but I feel like I'm close on this and was hoping you guys could help me figure out the last part

Given this query

SELECT
ca_organization.org_name AS campus,
p.host_name AS mcc,
ca_owned_resource.resource_name AS app_code,
COUNT( call_req.id ) AS password_reset_count
FROM call_req
INNER JOIN ca_contact ON call_req.log_agent = ca_contact.contact_uuid
INNER JOIN prob_ctg ON call_req.category = prob_ctg.persid
INNER JOIN ca_organization ON ca_contact.organization_uuid = ca_organization.organization_uuid
INNER JOIN ca_owned_resource ON substring( prob_ctg.sym, 0, 4 ) = substring( ca_owned_resource.resource_name, 0 , 4 )
INNER JOIN busmgt ON ca_owned_resource.own_resource_uuid = busmgt.hier_child
INNER JOIN ca_owned_resource p ON busmgt.hier_parent = p.own_resource_uuid
WHERE
( call_req.template_name IS NULL )
AND ( busmgt.ci_rel_type = 400027 )
AND ( p.resource_family = 400042 )
AND ( prob_ctg.sym LIKE '%password reset%' )
AND ( call_req.open_date >= 1280638800 )
AND ( call_req.open_date <= 1283317200 )
GROUP BY ca_organization.org_name, p.host_name, ca_owned_resource.resource_name


I want to add COUNT( call_req.id ) AS other_ticket_count which would be a wc of ( prob_ctg.sym NOT LIKE '%password reset%' ). I figure I'm going to have to do some aliasing here but I just can't figure it out. Any help?

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-09-22 : 11:56:51
Does this work? It's probably not as optimised as it could be but it is only a minor change to your query

SELECT
ca_organization.org_name AS campus,
p.host_name AS mcc,
ca_owned_resource.resource_name AS app_code,
SUM(CASE WHEN prob_ctg.sym LIKE '%password reset%' THEN 1 ELSE 0 END) AS password_reset_count,
SUM(CASE WHEN prob_ctg.sym NOT LIKE '%password reset%' THEN 1 ELSE 0 END) AS other_ticket_count,
FROM call_req
INNER JOIN ca_contact ON call_req.log_agent = ca_contact.contact_uuid
INNER JOIN prob_ctg ON call_req.category = prob_ctg.persid
INNER JOIN ca_organization ON ca_contact.organization_uuid = ca_organization.organization_uuid
INNER JOIN ca_owned_resource ON substring( prob_ctg.sym, 0, 4 ) = substring( ca_owned_resource.resource_name, 0 , 4 )
INNER JOIN busmgt ON ca_owned_resource.own_resource_uuid = busmgt.hier_child
INNER JOIN ca_owned_resource p ON busmgt.hier_parent = p.own_resource_uuid
WHERE
( call_req.template_name IS NULL )
AND ( busmgt.ci_rel_type = 400027 )
AND ( p.resource_family = 400042 )
-- AND ( prob_ctg.sym LIKE '%password reset%' )
AND ( call_req.open_date >= 1280638800 )
AND ( call_req.open_date <= 1283317200 )
GROUP BY ca_organization.org_name, p.host_name, ca_owned_resource.resource_name


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

Pr0FiT
Starting Member

7 Posts

Posted - 2010-09-22 : 12:04:09
That doesn't quite work. It actually occurred to me after posting this that i could just union the same query w/ diffrent wc's and add a hardcoded type column, which worked out great. i dont know much about optimization but the report team can deal w/ that :) thanks for the help
Go to Top of Page
   

- Advertisement -