Click here to Skip to main content
15,889,281 members
Home / Discussions / Database
   

Database

 
AnswerRe: SQL stored porcedures Pin
Frank Kerrigan13-Sep-07 6:11
Frank Kerrigan13-Sep-07 6:11 
AnswerRe: SQL stored porcedures Pin
Paul Conrad14-Sep-07 19:20
professionalPaul Conrad14-Sep-07 19:20 
QuestionQuery not returning distinct value Pin
miniThomas12-Sep-07 19:35
miniThomas12-Sep-07 19:35 
AnswerRe: Query not returning distinct value Pin
ritu432112-Sep-07 20:13
ritu432112-Sep-07 20:13 
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 
I attempting to extract data from a single table based on the two different criteria then presenting the information as one table. In the first instance I am trying to extact the date and count() of all messages received with a given time period(the query is based on createdDate). In the second intsatnce I am attempting to extrtact data based on it current status(i.e resolved, resaerched, open) I have created two temp table that provides me with the data I need now I need to group them by date so I can display the data by months for example:

Beginning Period Received Messages Resolved Issues
1/1/2007 15 6
2/1/07 8 19
3/1/07 25 10

And so forth. I have inclused the script any assistance will be great appreciated.


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[sp_MS_IssuesReport](@PeriodName varchar(50), @BeginningDate datetime, @EndDate datetime)AS
BEGIN
DECLARE

@Period datetime,
@MessagesReceived bigint,
@MessagesClosed bigint


SET NOCOUNT ON;

CREATE TABLE #MS_MessagesReceived(
DateCreated datetime,
IssuesReceived int,

)
CREATE TABLE #MS_MessagesStatus(
DateCreated datetime,
IssuesClosed int
)
CREATE TABLE #MS_MessagesReceivedAndStatuses(
DateCreated datetime,
IssuesReceived int,
IssuesClosed int
)


Insert Into #MS_MessagesReceived(DateCreated,IssuesReceived)
Select dbo.RPT_GetPeriod(@PeriodName, CreateDate) AS 'Period', count(CurrentStatusID) from Ms_threads
where CreateDate BETWEEN @BeginningDate and @EndDate
Group by CreateDate,CurrentStatusID
Order by CreateDate

Insert Into #MS_MessagesStatus(DateCreated, IssuesClosed)
Select dbo.RPT_GetPeriod(@PeriodName, StatusDate) AS 'Period',count(CurrentStatusID)from Ms_threads
where dbo.RPT_IsInquiryCompleted(CurrentStatusID) = 1
and StatusDate BETWEEN @BeginningDate and @EndDate
Group by StatusDate, CurrentStatusID
Order by StatusDate, CurrentStatusID

SELECT @MessagesReceived = count(IssuesReceived) from #MS_MessagesReceived
SELECT @MessagesClosed = count (IssuesClosed) from #MS_MessagesStatus
SELECT @Period =dbo.RPT_GetPeriod(@PeriodName, DateCreated) from #MS_MessagesReceived

INSERT INTO #MS_MessagesReceivedAndStatuses(DateCreated, IssuesReceived, IssuesClosed)
VALUES(@Period, @MessagesReceived, @MessagesClosed)

Select DateCreated 'Time Period Beginning' , IssuesReceived 'Issue Received', IssuesClosed 'Issue Closed'
from #MS_MessagesReceivedAndStatuses

Drop Table #MS_MessagesReceived
Drop Table #MS_MessagesStatus
Drop Table #MS_MessagesReceivedAndStatuses
END

Skan

If you knew it would not compile why didn't you tell me?!?!?!

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 
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 

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.