Extract last 7 days data based on current date using TSQL

  • Hi All,

    I am really struggling to get a script going for me (ofcourse i am not that good with scripting). Below is my scenario and any help regarding this is greatly appreciated.

    >>I had setup a performance monitor on one of our Windows Server 2008 and configured it to collect information every 15 secs and send the data to a SQL database.

    >>Perfmon has automatically created 3 tables and is sending the data into them.

    >>Two of those tables are

    CounterData (CounterID int, CounterDatetime char(24), CounterValue float...)---has the actual counter values

    COunterDetails (CounterID int, Machinename varchar(1024), Objectname varchar(1024), Countername varchar(1024)...)---Has the counter information

    >>Now in the CounterData table each counter has thousands of records per day.

    My Issue:

    I am trying to write a script which will give me the average value of each counter per day for the last 7 days starting from the current date.

    Please help me with this.

    Thanks

  • To get last 7 days of data, you could use some datetime formulas like this:

    WHERE DateColumn >= DATEADD( DAY, DATEDIFF(DAY, 0, GETDATE()) - 7, 0)

    AND DateColumn < GETDATE()

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply