Howdy, all. Pardon my denseness, apparently I don't know Dynamic SQL
as well as I should.
What I'm trying to do:
Run a stored procedure that, given a table name, will find the
previous Friday's data and stuff it back into the same table for
Saturday and Sunday.
Every table has an asof_date, which is the date the information is
from.
My current code is the following. The issue I'm running into is that
when I try to start adding variables (i.e. changing getdate() into a
variable so I can run it on Tuesday instead of Monday), things get
rapidly out of control.
The goal is to make this an SP so I can say "exec FridaySP
'mikes_lousy_db'" and have it find the previous friday's data, stuff
Saturday's/Sunday's, and quit.
I know I'm going about it the wrong way, especially after seeing
Erland's page on Dynamic SP, so hopefully someone can help. Thanks.
--grab Friday's data
' where asof_date = convert(char(10), getdate()-3,101)')
--update the asof_date to be Saturday's
update ##FridayInfo
set asof_date = convert(char(10),getdate()-2,101),
input_date = getdate()
--insert the updated records
--update the date to be Sunday, now.
update ##FridayInfo set asof_date = convert(char(10),getdate()-2,101)
--insert the updated records
drop table ##FridayInfo
Many thanks!
Michael