SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Creating a percentage column based on 2 know column values


Creating a percentage column based on 2 know column values

Author
Message
spyfly
spyfly
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 48
I am trying to create a query that will create a percentage based on 2 know column values

I want to make a column of percentage based on
Maxbps_In95 / Interfaces.InterfaceSpeed and
Maxbps_Out95 / Interfaces.InterfaceSpeed
So really I want 2 extra cloumns

Thanks

Here is the current query

SET NOCOUNT OFF
SET ROWCOUNT 0
DECLARE @StartDate DateTime
DECLARE @EndDate DateTime
SET @StartDate = DATEADD(d, DATEDIFF(d, 0, DATEADD(m, -1, DATEADD(d, 1 - day(getdate()), getdate()))), 0)
SET @EndDate = DATEADD(ms, -2,DATEADD(d, DATEDIFF(d, 0, DATEADD(d, 1 - day(getdate()), getdate())), 0))
SELECT 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,
Interfaces.InterfaceSpeed AS Interface_Speed
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
WHERE (1=1) AND
( (Nodes.TBU = 'TBU') AND (Interfaces.Link_Type LIKE '%Primary%') )
ORDER BY NodeName, Interface_Caption

ZZartin
ZZartin
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12995 Visits: 13815
Is there some reason you can't just add two new columns with those formulas to the SELECT?
Steve Jones
Steve Jones
SSC Guru
SSC Guru (327K reputation)SSC Guru (327K reputation)SSC Guru (327K reputation)SSC Guru (327K reputation)SSC Guru (327K reputation)SSC Guru (327K reputation)SSC Guru (327K reputation)SSC Guru (327K reputation)

Group: Administrators
Points: 327723 Visits: 20091
SET NOCOUNT OFF
;
SET ROWCOUNT 0
;
DECLARE @StartDate DATETIME
;
DECLARE @EndDate DATETIME
;
SET @StartDate
= DATEADD(
d
, DATEDIFF(
d
, 0
, DATEADD(
m
, -1
, DATEADD(
d
, 1 - DAY(GETDATE())
, GETDATE()
)
)
)
, 0
)
;
SET @EndDate
= DATEADD(
ms
, -2
, DATEADD(
d
, DATEDIFF(
d
, 0
, DATEADD(
d
, 1 - DAY(GETDATE())
, GETDATE()
)
)
, 0
)
)
;
SELECT
Interfaces.InterfaceId
, Nodes.NodeID
, NodeName = Nodes.Caption
, Vendor_Icon = Nodes.VendorIcon
, Interface_Caption = Interfaces.Caption
, Interface_Icon = Interfaces.InterfaceIcon
, Maxbps_In95
, Maxbps_Out95
, Maxbps_95
, Interface_Speed = Interfaces.InterfaceSpeed
, 'Thing1' = (Maxbps_In95 / Interfaces.InterfaceSpeed ) * 100
, 'Thing2' = (Maxbps_Out95 / Interfaces.InterfaceSpeed) * 100
FROM
Nodes
INNER JOIN Interfaces
ON Nodes.NodeID = Interfaces.NodeID
INNER JOIN (
SELECT
InterfaceID
, Maxbps_In95 = dbo.GetInBps95th(
InterfaceID
, @StartDate
, @EndDate
)
, Maxbps_Out95 = dbo.GetOutBps95th(
InterfaceID
, @StartDate
, @EndDate
)
, Maxbps_95 = dbo.GetMaxBps95th(
InterfaceID
, @StartDate
, @EndDate
)
FROM InterfaceTraffic
WHERE
InterfaceTraffic.DateTime >= @StartDate
AND InterfaceTraffic.DateTime <= @EndDate
GROUP BY InterfaceID
) AS TrafficStat
ON Interfaces.InterfaceID = TrafficStat.InterfaceID
WHERE
(1 = 1)
AND (
(Nodes.TBU = 'TBU')
AND (Interfaces.Link_Type LIKE '%Primary%')
)
ORDER BY
NodeName
, Interface_Caption
;


Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
spyfly
spyfly
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 48
thanks @Steve Jones, that worked perfectly... I am new to this I am sure you can tell, I swore I tried what you did for me but I guess I have missing something

thanks again
Steve Jones
Steve Jones
SSC Guru
SSC Guru (327K reputation)SSC Guru (327K reputation)SSC Guru (327K reputation)SSC Guru (327K reputation)SSC Guru (327K reputation)SSC Guru (327K reputation)SSC Guru (327K reputation)SSC Guru (327K reputation)

Group: Administrators
Points: 327723 Visits: 20091
Cheers

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search