|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 12:43 AM
Points: 582,
Visits: 1,601
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Monday, April 22, 2013 3:08 AM
Points: 49,
Visits: 374
|
|
a very nice article indeed, however i recently had the same issue on SQL Server 8.0, Is their a related atricle/method for SQL 8?
Knock Knock, Who's There?, sp underscore, sp underscore who? spid1, spid2, spid3....
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 12:43 AM
Points: 582,
Visits: 1,601
|
|
Hi Jordon, As you probably realise, SQL 2000 doesn't have CTEs or RowNumber.
I was happy to discover CTEs precisely because I'm hopeless at doing queries like the one below!! So here's something to get you started...
...but I'm sure someone will chip in with a complete / better solution.
select currow.ItemId, ( select max(PriceStartDate) from PriceHistory phPrev where phPrev.PriceStartDate < currow.PriceStartDate and phPrev.ItemId=currow.ItemId ) as OldPrice, currow.PriceStartDate, currow.Price from PriceHistory currow Change the smiley for a closing bracket.
Hope this helps....
David.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Monday, April 22, 2013 3:08 AM
Points: 49,
Visits: 374
|
|
hmmm, yes based on that i have come up with a simple sub-select approach:
select * from SELECT DailyMileageID, MileageAtStartOfShift, MileageAtEndOfShift, MileageAtEndOfShift - MileageAtStartOfShift AS DayMileage, MileageAtEndOfShift - (SELECT MileageAtStartOfShift FROM dbo.DailyMileages AS I WHERE (DailyMileageID = b.DailyMileageID + 1)) AS NightMileage, ShopID, DateEntered FROM dbo.DailyMileages AS b which works, but i am a little bothered about performance, but yes, thanks for the tip :
next task... convince this company to upgrade their sql server :D
Knock Knock, Who's There?, sp underscore, sp underscore who? spid1, spid2, spid3....
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 12:43 AM
Points: 582,
Visits: 1,601
|
|
Be careful about using DailyMileageID+1. You could have holes if it's an identity column (when you delete rows, for example), and also is the sort order definitely correct?
Look in your data for another way of identifying the next / previous row.
Regards,
David.
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 12:07 PM
Points: 431,
Visits: 583
|
|
As you mention in the article I maintain audit trails by storing both a start date and an end date in my history tables. How is the overall performance of the CTE method for extracting a point-in-time view of your data? Is it fast enough to handle reporting on demand?
Regards, Michael Lato
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Friday, May 17, 2013 12:22 PM
Points: 10,571,
Visits: 11,871
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, April 11, 2013 1:43 PM
Points: 34,
Visits: 115
|
|
For this date range technique, for the end date: nextrow.PriceStartDate AS EndDate I usually do: dateadd(day, -1, nextrow.PriceStartDate) AS EndDate
Also truncate to midnight the start/end date and any date comparisons to the range
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 12:43 AM
Points: 582,
Visits: 1,601
|
|
How is the overall performance of the CTE method for extracting a point-in-time view of your data? Is it fast enough to handle reporting on demand?
I haven't done any specific volume testing on this. All I can say is that I'm using it in production systems, without any noticeable performance hit. Obviously storing the data inline is going to be faster, but to what degree I honestly don't know.
I'm one of those developers who will often choose the elegant solution over the fastest solution, providing it is fast enough for the application being developed.
Regards,
David.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 6:23 AM
Points: 32,903,
Visits: 26,784
|
|
Jack Corbett (3/13/2008) Nice article. I like the fact that is clearly takes you from start to finish and offers a solution to a commonly encountered problem.
Agreed... and test data used was attached in the Resources area... nicely done.
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|