dbTalk Databases Forums  

Help with date

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Help with date in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
valdemirs
 
Posts: n/a

Default Help with date - 12-21-2009 , 05:22 AM






Hi:
Please, is there any way to summarize this sql command below to show
me only one data per day ?
Actually itīs show me 24 data ( one per hour):



SELECT TOP 10000 Nodes.Caption AS NodeName,
APM_AlertsAndReportsData.ComponentName AS Component_Name,
APM_ResponseTime.StatisticData AS StatisticsData,
APM_ResponseTime.DateTime AS DateTime

FROM
(Nodes INNER JOIN APM_AlertsAndReportsData ON (Nodes.NodeID =
APM_AlertsAndReportsData.NodeId)) INNER JOIN APM_ResponseTime ON
(APM_AlertsAndReportsData.ComponentId = APM_ResponseTime.ComponentID)


WHERE

( DateTime >= dateadd(mm,datediff(mm,0,getdate())-1,0) AND DateTime
<dateadd(mm,datediff(mm,0,getdate()),0) )


AND
(
(Nodes.Caption = 'SERV-ABP3') AND
(
(APM_AlertsAndReportsData.ComponentName = 'swap')

))



serv-abp3 swap 1 2009-11-26 00:00:00.000
serv-abp3 swap 1 2009-11-26 01:00:00.000
serv-abp3 swap 1 2009-11-26 02:00:00.000
serv-abp3 swap 1 2009-11-26 03:00:00.000
serv-abp3 swap 1 2009-11-26 04:00:00.000
serv-abp3 swap 1 2009-11-26 05:00:00.000
serv-abp3 swap 1 2009-11-26 06:00:00.000
serv-abp3 swap 1 2009-11-26 07:00:00.000
serv-abp3 swap 1,41666666666667 2009-11-26 08:00:00.000
serv-abp3 swap 2 2009-11-26 09:00:00.000
serv-abp3 swap 2 2009-11-26 10:00:00.000
serv-abp3 swap 2 2009-11-26 11:00:00.000
serv-abp3 swap 2 2009-11-26 12:00:00.000
serv-abp3 swap 2 2009-11-26 13:00:00.000
serv-abp3 swap 2 2009-11-26 14:00:00.000
serv-abp3 swap 2 2009-11-26 15:00:00.000
serv-abp3 swap 2 2009-11-26 16:00:00.000
serv-abp3 swap 1,83333333333333 2009-11-26 17:00:00.000
serv-abp3 swap 1 2009-11-26 18:00:00.000
serv-abp3 swap 1 2009-11-26 19:00:00.000
serv-abp3 swap 1 2009-11-26 20:00:00.000
serv-abp3 swap 1 2009-11-26 21:00:00.000
serv-abp3 swap 1 2009-11-26 22:00:00.000
serv-abp3 swap 1 2009-11-26 23:00:00.000

Reply With Quote
  #2  
Old   
Plamen Ratchev
 
Posts: n/a

Default Re: Help with date - 12-21-2009 , 12:37 PM






It is not very clear how you want to group your data (for example, do you want to summarize statistic data). Here is
generic form to get rid of the time portion (by setting it to midnight for all dates) and group by all columns, which
will eliminate the duplicate lines. You may want to use the SUM aggregate function for the StatisticData column and
remove it from the GROUP BY clause.

SELECT TOP 10000 Nodes.Caption AS NodeName,
APM_AlertsAndReportsData.ComponentName AS Component_Name,
APM_ResponseTime.StatisticData AS StatisticsData,
DATEADD(DAY, DATEDIFF(DAY, 0, APM_ResponseTime.[DateTime]), 0) AS [Date]
FROM Nodes
INNER JOIN APM_AlertsAndReportsData
ON Nodes.NodeID = APM_AlertsAndReportsData.NodeId
INNER JOIN APM_ResponseTime
ON APM_AlertsAndReportsData.ComponentId = APM_ResponseTime.ComponentID
WHERE [DateTime] >= DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP)-1, 0)
AND [DateTime] < DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP), 0)
AND Nodes.Caption = 'SERV-ABP3'
AND APM_AlertsAndReportsData.ComponentName = 'swap'
GROUP BY Nodes.Caption,
APM_AlertsAndReportsData.ComponentName,
APM_ResponseTime.StatisticData,
DATEADD(DAY, DATEDIFF(DAY, 0, APM_ResponseTime.[DateTime]), 0);

--
Plamen Ratchev
http://www.SQLStudio.com

Reply With Quote
  #3  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Help with date - 12-21-2009 , 03:59 PM



valdemirs (valdemirs (AT) gmail (DOT) com) writes:
Quote:
Please, is there any way to summarize this sql command below to show
me only one data per day ?
To show data once per day:

SELECT Nodes.Caption AS NodeName,
APM_AlertsAndReportsData.ComponentName AS Component_Name,
AVG(APM_ResponseTime.StatisticData) AS StatisticsData,
convert(char(10), APM_ResponseTime.DateTime, 112) AS DateTime
FROM ...
GROUP BY Nodes.Caption, APM_AlertsAndReportsData.ComponentName,
convert(char(10), APM_ResponseTime.DateTime, 112)

To group by the hour, just change char(10) to char(13)




--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
Reply




Thread Tools
Display Modes

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.