Bellow is code that shows how to get yesterday's date by adding to a specific date (in my example January 1, 2000) the amount of days that past since that date minus 1.
declare @dt datetime
set @dt = dateadd(dd,datediff(dd,'20000101',getdate())-1,'20000101')
select @dt, getdate()
As for the cursors – there are plenty of explanation about working with cursors on the internet. Here is one of those places – http://blog.sqlauthority.com/2007/01/01/sql-server-simple-example-of-cursor/%5B/url%5D.
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
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/