Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
uneek78
Starting Member
13 Posts |
Posted - 2013-01-16 : 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 CompletedDATEDIFF(minute, "dbo"."Order".CompleteDate, Report.BeginEditDate), --Study completed minus Start DictateDATEDIFF(minute, Report.BeginEditDate, Report.LastPrelimDate), --Start Dictate minus ApprovedDATEDIFF(minute, Report.LastPrelimDate, Report.LastSignDate) --Approved minus SignFROM "dbo"."Order", Report, AccountWHERE "dbo"."Order".CreateDate BETWEEN '01/01/2013 10:30:00' and '01/01/2013 10:32:00'; |
|
djj55
Constraint Violating Yak Guru
352 Posts |
Posted - 2013-01-16 : 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
52326 Posts |
Posted - 2013-01-16 : 23:38:55
|
what you're doing currently is cartesian product which doesnt make much sense.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
uneek78
Starting Member
13 Posts |
Posted - 2013-01-17 : 08:56:03
|
quote: Originally posted by visakh16 what you're doing currently is cartesian product which doesnt make much sense.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://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
52326 Posts |
Posted - 2013-01-17 : 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 MVPhttp://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 MVPhttp://visakhm.blogspot.com/ |
|
|
uneek78
Starting Member
13 Posts |
Posted - 2013-01-18 : 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 MVPhttp://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 MVPhttp://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
52326 Posts |
Posted - 2013-01-18 : 13:35:10
|
ok..good for you then------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|