Solved

SQL Question

Posted on 2016-08-04
1
40 Views
Last Modified: 2016-08-04
I'm trying to figure out this query for SQL Server

My table has records that are inserted as follows

note      process               start              stop
note1      myprocess       8/4/2016      
note1      myprocess                            8/5/2016


I want to group the two records on Note and Process and return a date difference between Start and Stop

Returned

Note               Process            DateTimeDiff
note1              myprocess      1


help?
0
Comment
Question by:keschuster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 34

Accepted Solution

by:
ste5an earned 500 total points
ID: 41743439
Rows, not records. Any chance to change your data loading?

Otherwise it is a simple GROUP BY:

SELECT  Note, 
        Process, 
        Min(Start), 
        Max(Stop), 
        DATEDIFF(DAY,Min(Start), Max(Stop))
FROM yourTable
GROUP BY Note, Process;

Open in new window

0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question