SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 DATEDIFF IF & Median In Minutes On Same Name
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

uneek78
Starting Member

13 Posts

Posted - 01/16/2013 :  09:23:14  Show Profile  Reply with Quote
In the DATEDIFF section for "DATEDIFF(minute, Report.BeginEditDate, Report.LastPrelimDate)", I would like when there is no value in the "LastPrelimDate" column for it to instead do "DATEDIFF(minute, Report.BeginEditDate, Report.LastSignDate)". Additionally, I would also like when the LoginName is the same for the minutes in the DATEDIFF columns to add together and give the median. It sounds really hard to me, but maybe this is a piece of cake to someone else. I sure hope so!



SELECT Account.LoginName, "dbo"."Order".CreateDate, "dbo"."Order".CompleteDate,
Report.BeginEditDate, Report.LastPrelimDate,
Report.LastSignDate, Report.IsAddendum,
DATEDIFF(minute, "dbo"."Order".CreateDate, "dbo"."Order".CompleteDate), --Order created minus Study Completed
DATEDIFF(minute, "dbo"."Order".CompleteDate, Report.BeginEditDate), --Study completed minus Start Dictate
DATEDIFF(minute, Report.BeginEditDate, Report.LastPrelimDate), --Start Dictate minus Approved
DATEDIFF(minute, Report.LastPrelimDate, Report.LastSignDate) --Approved minus Sign

FROM "dbo"."Order", Report, Account

WHERE "dbo"."Order".CreateDate BETWEEN '01/01/2013 10:30:00' and '01/01/2013 10:32:00'
;

djj55
Constraint Violating Yak Guru

USA
320 Posts

Posted - 01/16/2013 :  12:53:19  Show Profile  Reply with Quote
First you need to have a relationship between the three tables, joins would be nice. I also would suggest using an alias for Order table "dbo.Order Order,".

djj
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/16/2013 :  23:38:55  Show Profile  Reply with Quote
what you're doing currently is cartesian product which doesnt make much sense.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

uneek78
Starting Member

13 Posts

Posted - 01/17/2013 :  08:56:03  Show Profile  Reply with Quote
quote:
Originally posted by visakh16

what you're doing currently is cartesian product which doesnt make much sense.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Sorry, I'm not sure what cartesian product is, but it works. I'm probably not as SQL savvy as you; I'm just happy to see the data I need show up.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/17/2013 :  22:54:35  Show Profile  Reply with Quote
quote:
Originally posted by uneek78

quote:
Originally posted by visakh16

what you're doing currently is cartesian product which doesnt make much sense.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Sorry, I'm not sure what cartesian product is, but it works. I'm probably not as SQL savvy as you; I'm just happy to see the data I need show up.


Are you sure its the data you wanted? Currently it just pulls all possible combinations of data from three tables without any relationship. In business terms it doesnt make any sense. But if you're sure this is what you're looking at, then i dont have any issue

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

uneek78
Starting Member

13 Posts

Posted - 01/18/2013 :  09:23:33  Show Profile  Reply with Quote
quote:
Originally posted by visakh16

quote:
Originally posted by uneek78

quote:
Originally posted by visakh16

what you're doing currently is cartesian product which doesnt make much sense.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Sorry, I'm not sure what cartesian product is, but it works. I'm probably not as SQL savvy as you; I'm just happy to see the data I need show up.


Are you sure its the data you wanted? Currently it just pulls all possible combinations of data from three tables without any relationship. In business terms it doesnt make any sense. But if you're sure this is what you're looking at, then i dont have any issue

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Fortunately it is the data I need. I don't need the data to be related. They're just time stamps from unrelated things that happened to the order and/or report at different time periods. I am able to match this data up with the information in our front end application.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/18/2013 :  13:35:10  Show Profile  Reply with Quote
ok..good for you then

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000