Solved

SQL Question

Posted on 2016-08-04
1
29 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
1 Comment
 
LVL 33

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

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now