MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 5th, 2012, 03:35 PM
QA_Keith QA_Keith is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 QA_Keith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 8 sec
Reputation Power: 0
Count only one field of a query.

I can say it...I need help.

We use HP Quality Center here at work and the dev team is really protective to the point where they will not even allow my to make an inline table. What I have is a query that checks for open defects in our DB but in order to get it to do it properly I need to have many fields in the select statement. My manager wants a count of the defects but because of all the fields, count treats each entry in the return as unique so I end up with every row having a 1 in the count.

Here is the query:

SELECT DISTINCT

count (BUG.BG_BUG_ID) as #, BUG.BG_BUG_ID AS Defect_Id, BUG.BG_DETECTION_VERSION AS Detected_in_Version, BUG.BG_PROJECT AS Project, BUG.BG_STATUS AS Status,
BUG.BG_DETECTED_BY AS Detected_by, LINK.LN_ENTITY_TYPE AS Link_Type, TEST.TS_TEST_ID AS Test_ID10, TEST.TS_NAME AS Test_Name

FROM
td.BUG AS BUG
LEFT OUTER JOIN
td.LINK AS LINK ON BUG.BG_BUG_ID = LINK.LN_BUG_ID
FULL outer JOIN
td.STEP AS STEP
INNER JOIN
td.TEST AS TEST ON STEP.ST_TEST_ID = TEST.TS_TEST_ID ON LINK.LN_ENTITY_ID = STEP.ST_ID
full outer join
td.TESTCYCL ON td.TESTCYCL.TC_TESTCYCL_ID = LINK.LN_ENTITY_ID

WHERE
(BUG.BG_PROJECT IN ('EWC', 'SCBP WC'))
AND
(BUG.BG_STATUS NOT IN ('Closed', 'Duplicate', 'Rejected', 'Withdrawn'))
AND
(LINK.LN_ENTITY_TYPE ='STEP' or LINK.LN_ENTITY_TYPE is NULL or LINK.LN_ENTITY_TYPE = 'TEST' or LINK.LN_ENTITY_TYPE = 'TESTCYCL')

group by BUG.BG_BUG_ID

order by BUG.BG_BUG_ID

What I need is a count of just bug.bg_bg_id to be placed in the first field

MOCKED UP Results: (This is what I need it to do)

# of occurances Defect_Id Detected_in_Version Project Status Detected_by Link_Type Test_ID10 Test_Name
2 5757 201204 SCBP WC Deferred STEP 68211 States&Mod_ARAP_Mod_NB_Edit_msg_TC004
2 5757 201204 SCBP WC Deferred STEP 68212 States&Mod_ARAP_Mod_NB_Edit_msg_TC005
2 5759 201204 SCBP WC Deferred STEP 68211 States&Mod_ARAP_Mod_NB_Edit_msg_TC004
2 5759 201204 SCBP WC Deferred STEP 68212 States&Mod_ARAP_Mod_NB_Edit_msg_TC005

This is what it does:

# of occurances Defect_Id Detected_in_Version Project Status Detected_by Link_Type Test_ID10 Test_Name
1 5757 201204 SCBP WC Deferred STEP 68211 States&Mod_ARAP_Mod_NB_Edit_msg_TC004
1 5757 201204 SCBP WC Deferred STEP 68212 States&Mod_ARAP_Mod_NB_Edit_msg_TC005
1 5759 201204 SCBP WC Deferred STEP 68211 States&Mod_ARAP_Mod_NB_Edit_msg_TC004
1 5759 201204 SCBP WC Deferred STEP 68212 States&Mod_ARAP_Mod_NB_Edit_msg_TC005

Any help would be greatly appreciated.

Reply With Quote
  #2  
Old October 5th, 2012, 09:38 PM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,357 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 4 h 42 m 44 sec
Reputation Power: 4140
Quote:
Originally Posted by QA_Keith
... count treats each entry in the return as unique so I end up with every row having a 1 in the count.
no, COUNT works just fine -- it's your GROUP BY that's creating the results of 1

every BUG.BG_BUG_ID is unique, correct? so you're asking it to count how many values each unique id has, and that's always gonna be equal to 1

besides, how come you're trying to count them at the same time as printing them out?

if you're gonna print them out, use your application language (vb or asp or whatever) to count them as you're printing them
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old October 8th, 2012, 07:34 AM
QA_Keith QA_Keith is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 QA_Keith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 8 sec
Reputation Power: 0
Quote:
Originally Posted by r937
no, COUNT works just fine -- it's your GROUP BY that's creating the results of 1

every BUG.BG_BUG_ID is unique, correct? so you're asking it to count how many values each unique id has, and that's always gonna be equal to 1

besides, how come you're trying to count them at the same time as printing them out?

if you're gonna print them out, use your application language (vb or asp or whatever) to count them as you're printing them


Bug IDs are not unique. One Bug ID can be holding up multiple test cases so a Bug ID can be in multiple rows.

Also, I am not printing them out. The examples given are how they appear on the query return.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Count only one field of a query.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap