Trying to query for everything last month. This bit works great in SQL...what is the equivalent in SWQL?
DateTime BETWEEN DATEADD(MONTH,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) AND DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))
I think this is the logic you'd want for the WHERE clause:
<span class="s5">WHERE</span><span class="s0"> </span><span class="s19">DateTime</span><span class="s0"> </span><span class="s5">BETWEEN</span><span class="s0"> </span><span class="s19">DATETRUNC</span><span class="s10">(</span><span class="s7">'month'</span><span class="s10">,</span><span class="s0"> </span><span class="s19">AddDate</span><span class="s10">(</span><span class="s7">'month'</span><span class="s10">,</span><span class="s0"> </span><span class="s4">-1</span><span class="s10">,</span><span class="s0"> </span><span class="s19">GETDATE</span><span class="s10">()))</span><span class="s0"> </span><span class="s5">AND</span><span class="s0"> </span><span class="s19">DATETRUNC</span><span class="s10">(</span><span class="s7">'month'</span><span class="s10">,</span><span class="s0"> </span><span class="s19">GETDATE</span><span class="s10">())</span><span class="s0"> </span>
<span class="s0"></span>
Did you look at Date/Time Functions on the Orion SDK wiki?
Yes, and frankly it just frustrates me that SWQL is so similar, yet different.
What are you specifically looking for? I'm seeing minutes and months above, but I'm not 100% what the WHERE clause should show. (Sorry - I'm only an accidental SQL person)
He said 'Last month, so maybe:
SELECT i.INTERFACEID,i.OutPercentUtil,i.DatetimeFROM Orion.NPM.InterfaceTraffic i--WHERE i.interfaceid = '10075' AND ((i.DateTime BETWEEN DATEADD(MONTH,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) AND DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) <- SQL WHERE i.interfaceid = '10075' AND (i.DateTime BETWEEN (adddate ('month',-1,GETDATE())) and GETDATE()) -- <- SWQLORDER BY DATETIME DESC