dcsimg
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2010
    Posts
    1

    Help on whriting a SQL Script / statement

    Hi I Have som problem whriting a SQl Script and i really apriciate if some one can help me out.

    Im running a SQL 2005 Database

    The table look like this, and are named DataLog

    DataAndtime Value Tagname
    02/11/2010 10:30:00 22 Valve
    02/11/2010 10:35:00 55 P2
    02/11/2010 10:40:00 54 Valve
    02/11/2010 10:45:00 77 P2
    02/11/2010 10:50:00 88 Valve
    02/11/2010 10:55:00 12 Valve
    02/11/2010 11:00:00 2 P2


    I like to the dateandtime + the Max value + the Tagname back from my statement.

    So something like this.


    Tagname DateAndTime Value
    Valve 02/11/2010 10:50:00 88
    P2 02/11/2010 10:45:00 77


    Could someone help me out with this.

    Beste Regards
    Tino Jørgensen
    Denmark

  2. #2
    Join Date
    Jan 2011
    Posts
    2
    SELECT Tagname, DateAndTime, Max(Value) FROM DataLog GROUP BY Tagname

  3. #3
    Join Date
    Mar 2011
    Location
    Toledo Ohio
    Posts
    2
    SELECT Tagname,
    MAX(DateAndTime),
    MAX(Value)
    FROM DataLog
    WHERE Value = (Select MAX(Value)
    FROM DataLog As B
    WHERE B.TagName = DataLog.TagName)
    GROUP BY TagName
    ORDER BY TagName DESC;

  4. #4
    Join Date
    Mar 2011
    Location
    Toledo Ohio
    Posts
    2
    This will not work because DateAndTime not in Group BY Clause.

  5. #5
    Join Date
    Mar 2011
    Posts
    2
    Try this:

    select DataAndtime , Value , Tagname from #temp1
    where Value in (select MAX(Value) from #temp1 group by Tagname)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •