Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Query question

Posted on 2011-02-15
3
Medium Priority
?
1,388 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
3 Comments
 
LVL 27

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 1000 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 1000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

877 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