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
 General SQL Server Forums
 New to SQL Server Programming
 Adding a date coloumn

Author  Topic 

cocofuc25
Starting Member

14 Posts

Posted - 2014-05-02 : 12:07:23
hi guys

i have a query like following

SET NOCOUNT OFF
SET ROWCOUNT 0

DECLARE @StartDate DateTime
DECLARE @EndDate DateTime

SET @StartDate = CAST (DATEDIFF(d, 0, DATEADD(d, 1 - day(getdate()), getdate()))as datetime)
SET @EndDate = GetDate()

SELECT
/*Convert(DateTime,Floor(Cast((DateTime) as Float)),0) AS SummaryDate,
*/Interfaces.InterfaceId,
Nodes.NodeID,
Nodes.Caption AS NodeName,
Nodes.VendorIcon AS Vendor_Icon,
Interfaces.Caption AS Interface_Caption,
Interfaces.InterfaceIcon AS Interface_Icon,
Maxbps_In95,
Maxbps_Out95,
Maxbps_95

FROM Nodes
INNER JOIN Interfaces ON Nodes.NodeID = Interfaces.NodeID
INNER JOIN (
SELECT InterfaceID,
dbo.GetInBps95th(InterfaceID, @StartDate, @EndDate) AS Maxbps_In95,
dbo.GetOutBps95th(InterfaceID, @StartDate, @EndDate) AS Maxbps_Out95,
dbo.GetMaxBps95th(InterfaceID, @StartDate, @EndDate) AS Maxbps_95
FROM InterfaceTraffic
WHERE InterfaceTraffic.DateTime >= @StartDate AND InterfaceTraffic.DateTime <= @EndDate
GROUP BY InterfaceID
) TrafficStat
ON Interfaces.InterfaceID = TrafficStat.InterfaceID /*inner join InterfaceTraffic on trafficstat.InterfaceID = InterfaceTraffic.InterfaceID
*/
WHERE
(Interfaces.Caption LIKE '%TO LA%') OR
(Interfaces.Caption LIKE '%TKM%') OR
(Interfaces.Caption LIKE '%TLKM%') OR
(Interfaces.Caption LIKE '%XL%') OR
(Interfaces.Caption LIKE '%TELKOM%') OR
(Interfaces.Caption LIKE '%MPLS%')

/*GROUP BY Convert(DateTime,Floor(Cast((DateTime) as Float)),0), interfaces.InterfaceID, nodes.NodeID, nodes.Caption, nodes.VendorIcon, interfaces.caption, Interfaces.InterfaceIcon, trafficstat.Maxbps_95, trafficstat.Maxbps_In95, TrafficStat.Maxbps_Out95
*/
ORDER BY NodeName, Interface_Caption


and when i execute it, it gave a return that i expected, but then i want to add a date coloumn on the first coloumn, i have tried many thinks but still doesnt gave me what i want

is there any idea ??

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-05-02 : 12:18:01
Where do you want to get the date from?
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-05-02 : 12:20:43
What is not working? Are you getting an error or unexpected results? Do you really have a column called DateTime? It's hard to tell what you trying to do because you've commented out most the query.

If you want to post your DDL, Sample data and expected output we can help you better. Here are some links that can help you provide that:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

cocofuc25
Starting Member

14 Posts

Posted - 2014-05-02 : 14:02:06
thanks for all reply

the query above only give me a result without any coloumn of date, and i want to add it, for instance, i would like to have a return as following

Date : 03/05/2014
InterfaceID : 309
NodeID : 380
NodeName : France
VendorIcon : Cisco
Interface Caption : Interface FastEthernet 1/0
Interface Icon : FastEthernet
MaxBps_In95 : 3892 bps
MaxBps_Out95 : 4932 bps
MaxBps_Max95 : 5540 bps

but what i get when execute the query i dont get Date coloumn on the result, and i need that coloumn to be added into the result for report purpose
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-05-02 : 14:26:18
I hate to be captain obvious, but did you uncomment the column you want?
Go to Top of Page

cocofuc25
Starting Member

14 Posts

Posted - 2014-05-05 : 03:03:28
yes, if i uncomment the coloumn i want, the process query never stop and need to be stop forcely,

any idea ??
Go to Top of Page
   

- Advertisement -