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 |
|
mortolee
Starting Member
1 Post |
Posted - 2007-11-22 : 12:15:19
|
Howdy,Im trying to retrieve data from a couple of tables using the following...SELECT SBM.ExternalBatchID,(SELECT MAX(EndDateTime) FROM dbo.StatsModuleLaunch AS SML WHERE (SML.ModuleLaunchID = SBM.ModuleLaunchID) AND (SML.ModuleUniqueID = 'scan.exe'))FROM dbo.StatsBatchModule AS SBMORDER BY SBM.ExternalBatchID ASC Works fine but for one thing, it brings back 1 row for each ExternalBatchID with the latest scan date and time (which i want), but it also brings back some Null rows (which i dont want)Here is an example of the retrieved data...89 19/11/2007 16:33:1189 NULL90 19/11/2007 16:32:5690 NULL91 19/11/2007 16:34:2691 NULL91 NULL91 NULL92 NULL92 22/11/2007 10:00:1092 NULL92 NULL92 NULL92 NULL92 NULL92 NULL92 NULL92 NULL92 NULL92 NULL92 NULL92 NULL92 NULL92 NULL92 NULL92 NULL92 NULL92 NULL93 22/11/2007 12:32:5793 NULL93 NULL93 NULL93 NULL93 NULL93 NULL93 NULL93 NULL93 NULL93 NULL94 NULL94 NULL94 22/11/2007 12:53:0394 NULL95 NULL95 NULL95 22/11/2007 12:57:2695 NULL95 NULL95 NULL95 NULL96 NULL96 22/11/2007 12:58:5897 NULL97 NULL97 22/11/2007 13:01:1897 NULL97 NULL98 NULL98 NULL98 NULL98 NULL98 NULL98 NULL98 NULL98 NULL98 NULL98 NULL98 22/11/2007 13:04:5298 NULL98 NULL99 NULL99 22/11/2007 13:57:3099 NULL99 NULL99 NULL100 22/11/2007 14:04:57100 NULL100 NULL100 NULL100 NULL101 NULL101 22/11/2007 14:09:24101 NULL101 NULL102 NULL102 NULL103 NULL103 22/11/2007 14:19:31103 NULL103 NULL104 NULL104 NULL104 NULL104 22/11/2007 15:01:32105 22/11/2007 15:24:11105 NULL105 NULL105 NULL105 NULL106 22/11/2007 15:27:55106 NULL106 NULL106 NULL107 NULL107 22/11/2007 15:31:06107 NULL107 NULL107 NULLThere are multiple entries in StatsBatchModule for 107 above, but i want to retrieve only the latest date/time with the 'scan.exe' value from StatsModuleLaunch, which doesnt have ExternalBatchID by the way.So i want to be getting:89 19/11/2007 16:33:1190 19/11/2007 16:32:5691 19/11/2007 16:34:2692 22/11/2007 10:00:1093 22/11/2007 12:32:5794 22/11/2007 12:53:0395 22/11/2007 12:57:2696 22/11/2007 12:58:5897 22/11/2007 13:01:1898 22/11/2007 13:04:5299 22/11/2007 13:57:30100 22/11/2007 14:04:57101 22/11/2007 14:09:24103 22/11/2007 14:19:31104 22/11/2007 15:01:32105 22/11/2007 15:24:11106 22/11/2007 15:27:55107 22/11/2007 15:31:06I've tried quite a lot including disctinct options and group by. but no luck.Cheers,Lee |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2007-11-22 : 12:51:06
|
| [code]SELECT SBM.ExternalBatchID, MAX(SML.EndDateTime) AS EndDateTimeFROM dbo.StatsBatchModule SBM JOIN dbo.StatsModuleLaunch SML ON SMB.ModuleLaunchID = SBL.ModuleLaunchIDWHERE SML.ModuleUniqueID = 'scan.exe'GROUP BY SBM.ExternalBatchID[/code] |
 |
|
|
|
|
|