I am attempting to insert a copy of a row from one table into another table with the same schema, with the addition of one column (a timestamp) to provide a ‘history’ of the first table in MS Sql Server 2005.
So, my query, without the additional column would be:
'SELECT INTO [WebsiteHistory] FROM [Website]'
I want to populate the timestamp column as well, but am not sure how to best do this. I’d like to do something like:
'SELECT Website.*, '' + DateTime.Now.ToShortDateString() + '' INTO [WebsiteHistory] FROM [Website]'
But that shouldn’t work, especially if the timestamp column is not the last one. Is there any way to do this?
Be warned. This works, but it is neither nice nor recommendable:
This assumes
WebsiteHistoryhas the same structure asWebsite(you said it has), plus there is one additionalDATETIMEfield.Better is this, because it is much more fail-safe (at the expense of being more verbose):