Posted by kevin on 11/06/07 14:16
Right, I used your handy answers to get a solution that worked.. Your
last method was the one to use but i left it running for 3 hours and
it still hadn't returned any results! (and it's a stupidly high spec
server with pretty much just sql on there)
anyway.. so in SQL Server managment studio i found the "Views" section
(sorta like tempory tables i presume) and popped this into a new one
call kev_bin.
WITH Bin1 AS (SELECT ItemID, MAX(DateTimeCreated) AS MDate
FROM dbo.BinItem AS Bin1
GROUP BY ItemID)
SELECT Bin2.ItemID, Bin2.BinName
FROM dbo.BinItem AS Bin2 INNER JOIN
Bin1 AS Bin1 ON Bin2.ItemID = Bin1.ItemID
AND Bin2.DateTimeCreated = Bin1.MDate
I could then go back to my orignal SQL and use the following to grap
the data from the newly created table kev_bin above:
Select ... .. ...
kbin.BinName as location
>From ...
....
dbo.kev_bin kbin
....
WHERE ..
item.ItemID = kbin.ItemID
.....
and this runs in about 20 seconds :D
thanks again for all your help, i couldn't have done it without!
[Back to original message]
|