I often get asked to provide some data from SQL Server to someone in another department. These are typically one-off requests and the people asking for the data usually don’t have database experience, so I put the data into an Excel spreadsheet and email it to them. Occasionally, that person will come back to me sometime later, maybe weeks or months later, and either ask for an updated copy of the same data or want me to update those records in the database in some way.
These requests make me nervous because I rarely can remember the exact SELECT statement I used to get them the data in the first place. And if I then generate the data again and there are missing or additional records, they usually spot it and then we have to launch an investigation of why the data differs from before and which data do they really want, etc. Lately, I’ve started doing something that helps me avoid that. Now, when I send someone data in a spreadsheet, I add a worksheet to the file and copy and paste the SELECT statement I used into it. Most the time, the user never notices. And when they come back to me later, I simply ask them if they still have the original spreadsheet I sent them. They almost always do, so it’s easy to get my original SELECT statement back and guarantee that I’m pulling data based on exactly the same criteria as previously.