Click here to Skip to main content
15,922,630 members
Home / Discussions / Database
   

Database

 
GeneralRe: Query not returning distinct value Pin
/randz12-Sep-07 23:25
/randz12-Sep-07 23:25 
AnswerRe: Query not returning distinct value Pin
Michael Potter13-Sep-07 4:46
Michael Potter13-Sep-07 4:46 
GeneralRe: Query not returning distinct value Pin
Frank Kerrigan13-Sep-07 6:15
Frank Kerrigan13-Sep-07 6:15 
QuestionTrying to extract data from a single table Pin
Skanless12-Sep-07 8:18
Skanless12-Sep-07 8:18 
AnswerRe: Trying to extract data from a single table Pin
andyharman13-Sep-07 2:32
professionalandyharman13-Sep-07 2:32 
GeneralRe: Trying to extract data from a single table Pin
Skanless13-Sep-07 5:46
Skanless13-Sep-07 5:46 
GeneralRe: Trying to extract data from a single table Pin
Skanless13-Sep-07 5:54
Skanless13-Sep-07 5:54 
GeneralRe: Trying to extract data from a single table Pin
andyharman13-Sep-07 6:45
professionalandyharman13-Sep-07 6:45 
Hi Skan

How about:
SELECT dbo.RPT_GetPeriod(@PeriodName, A.PeriodDate) AS Period,
    SUM(A.IssueReceived) AS IssuesReceived,
    SUM(A.IssueClosed) AS IssuesClosed
FROM (
  SELECT CreateDate AS PeriodDate,
      1 AS IssueReceived,
      0 AS IssueClosed
    FROM Ms_threads
    WHERE CreateDate BETWEEN @BeginningDate and @EndDate
  UNION ALL
  SELECT StatusDate AS PeriodDate,
      0 AS IssueReceived,
      dbo.RPT_IsInquiryCompleted(CurrentStatusID) AS IssueClosed
    FROM Ms_threads
    WHERE StatusDate BETWEEN @BeginningDate and @EndDate
) A
GROUP BY A.PeriodDate
ORDER BY A.PeriodDate
The select statements within the from-clause count the issues openned and closed during the selected period. The outside select statement then groups everything together.

The technique is fairly common. If you have problems understanding what it is doing then run each of the select statements individually.

Regards
Andy

If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message".

GeneralRe: Trying to extract data from a single table Pin
Skanless13-Sep-07 8:00
Skanless13-Sep-07 8:00 
QuestionGetting Top 10 results per month/year Pin
_Joao_12-Sep-07 0:33
_Joao_12-Sep-07 0:33 
AnswerRe: Getting Top 10 results per month/year Pin
Blue_Boy12-Sep-07 3:19
Blue_Boy12-Sep-07 3:19 
GeneralRe: Getting Top 10 results per month/year Pin
Frank Kerrigan12-Sep-07 5:36
Frank Kerrigan12-Sep-07 5:36 
GeneralRe: Getting Top 10 results per month/year Pin
Colin Angus Mackay12-Sep-07 5:53
Colin Angus Mackay12-Sep-07 5:53 
GeneralRe: Getting Top 10 results per month/year Pin
Pete O'Hanlon12-Sep-07 9:18
mvePete O'Hanlon12-Sep-07 9:18 
GeneralRe: Getting Top 10 results per month/year Pin
_Joao_12-Sep-07 11:41
_Joao_12-Sep-07 11:41 
GeneralRe: Getting Top 10 results per month/year Pin
yahao12-Sep-07 13:05
yahao12-Sep-07 13:05 
GeneralRe: Getting Top 10 results per month/year Pin
andyharman13-Sep-07 6:57
professionalandyharman13-Sep-07 6:57 
Questioncan i send emails in this way? Pin
prasadbuddhika11-Sep-07 17:49
prasadbuddhika11-Sep-07 17:49 
AnswerRe: can i send emails in this way? Pin
Frank Kerrigan12-Sep-07 5:39
Frank Kerrigan12-Sep-07 5:39 
QuestionHow to filter? Pin
shyne711-Sep-07 7:25
shyne711-Sep-07 7:25 
AnswerRe: How to filter? Pin
Christian Graus11-Sep-07 7:39
protectorChristian Graus11-Sep-07 7:39 
GeneralRe: How to filter? Pin
shyne711-Sep-07 8:14
shyne711-Sep-07 8:14 
GeneralRe: How to filter? Pin
Pete O'Hanlon11-Sep-07 9:59
mvePete O'Hanlon11-Sep-07 9:59 
GeneralRe: How to filter? Pin
shyne711-Sep-07 10:07
shyne711-Sep-07 10:07 
GeneralRe: How to filter? Pin
Pete O'Hanlon11-Sep-07 10:11
mvePete O'Hanlon11-Sep-07 10:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.