| Author |
Topic  |
|
|
uneek78
Starting Member
13 Posts |
Posted - 01/16/2013 : 09:23:14
|
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
Yak Posting Veteran
USA
84 Posts |
Posted - 01/16/2013 : 12:53:19
|
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 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 01/16/2013 : 23:38:55
|
what you're doing currently is cartesian product which doesnt make much sense.
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
uneek78
Starting Member
13 Posts |
Posted - 01/17/2013 : 08:56:03
|
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. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 01/17/2013 : 22:54:35
|
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/
|
 |
|
|
uneek78
Starting Member
13 Posts |
Posted - 01/18/2013 : 09:23:33
|
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. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 01/18/2013 : 13:35:10
|
ok..good for you then
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
| |
Topic  |
|