Solved

Query question

Posted on 2011-02-15
3
1,384 Views
Last Modified: 2012-05-11
I have a query that pulls some column values. One of the columns is a date called "Upload Date".

ex. Select this, that, theother, Uploaddate
      From thistable
      Where status=1

Now I want to basically add 1 more column called "Completed Date" to my resultset. For this,I would need to tweak the Where clause.

  ex. Select this, that, theother,CompletedDate      
         From thistable
        Where status=3

Then I want to Use DateDiff() function to get the days difference between "Upload Date" and "CompletedDate"  and call that value "Turnaround" .

So essentially if we left the where clause out what I want is this :
  ex. Select this, that, theother,UploadDate ,CompletedDate,Turnaround"    
         From thistable


How to do it? Any advice would be greatly appreciated.


     
0
Comment
Question by:jazzcatone
[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
3 Comments
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 34899483
What would you want to see for Turnaround when the status value is not 3 (complete)?

The general query would look like:
Select this, that, theother,UploadDate ,CompletedDate, DATEDIFF(day, UploadDate, CompletedDate) AS Turnaround From thistable
0
 
LVL 41

Assisted Solution

by:Sharath
Sharath earned 250 total points
ID: 34899675
I assume that you have UploadDate and CompletedDate in two different rows for the same combination of this,that and theother.
You can try like this.
select this,that,theother,DATEDIFF(DAY,UploadDate,CompletedDate)
  from (
select this,that,theother,
       max(Case Status when 1 then UploadDate end) UploadDate,
       max(Case Status when 3 then CompletedDate end) CompletedDate
  from thistable
 group by this,that,theother) t1

Open in new window

0
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 250 total points
ID: 34899728
You need a field that identifies the record when it is uploaded and when it is completed

then the query could be
Select this, that, theother, Uploaddate, B.CompletedDate, DATEDIFF(day, A.UploadDate, B.CompletedDate) AS Turnaround
From thistable A
inner join (select SomeID, CompletedDate
            From thistable
            Where status=3) B on B.SomeID = A.SomeID
where A.status=1

Open in new window

0

Featured Post

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

628 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