I would like to select dynamically all entries from last two months, and without entering date range in my query.
Here is my simple code:
SELECT Customer_Name, Date FROM table_Customer; all data between last two month
Thanks in advance for your help
SELECT
ME.FullName,
R.RuleDefaultName,
PR.ObjectName,
PR.CounterName,
P.DateTime,
P.SampleCount,
P.MinValue,
P.MaxValue,
P.AverageValue,
P.StandardDeviation
FROM
Perf.vPerfHourly P
INNER JOIN vManagedEntity ME ON
P.ManagedEntityRowId = ME.ManagedEntityRowId
INNER JOIN vPerformanceRuleInstance PRI ON
P.PerformanceRuleInstanceRowId = PRI.PerformanceRuleInstanceRowId
INNER JOIN vPerformanceRule PR ON
PRI.RuleRowId = PR.RuleRowId
INNER JOIN vRule R ON
PRI.RuleRowId = R.RuleRowId
SELECT Customer_Name, Dt
FROM table_Customer
where dt >= dateadd(day, -60, getdate())
Or
SELECT Customer_Name, Dt
FROM table_Customer
where dt >= dateadd(month, -2, getdate())
You should make sure not to use reserved keywords as column names.
Make sure you replace dt
with the appropriate date
column. The solution assumes you would need the previous 2 months data starting with the current date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With