Eric,
Eric?
I appreciate your feedback but something is not working with your script. I am getting the error message below:
Msg 137, Level 15, State 2, Line 11
Must declare the scalar variable "@rundate".
Eh, Tshindaye, excuse me, but are you trying to pull my legs? Or do you really think that @rundate and @rundat would be two different variables? If you can mangle my name with quite a few letters, may have I have the liberty to mangle one of your variable
names with a single letter?
My attitude to these forums have always been that I don't feel like spoonfeeding people a solution to certain problem, but rather giving them something they can learn from and use again in the future. For this reason, I also expect people to look at
the solutions from a wider perspective. That is, they don't use embrace the solution blindly, but they look at it, take it a part, until they understand how it works. In such a process, fixing simple typos like this one comes out automatically.
If you have never encountered sp_executesql before, I have more information about it in my article on dynamic SQL:
http://www.sommarskog.se/dynamic_sql.html