I'm in a bit of a hurry to update some data...I want to make sure I get it right the first time as this is production data.
Here's the structure:
I have a field called 'PostDate' that has wrong data in it and I need to fix it. The correct value exists in another table. And yes, I do indeed have a foreign key to link the two tables together (let's call the two tables "myTransactions" table and "myFiles" table). The myFile table has 'FileIDnum' as its primary key. The myTransactions table has 'BatchID' as the foreign key that links back to 'FileIDnum' ('PostDate' is found in 'myTransactions').
Now here is the goal:
The myFile table has a field called 'FileName' which is a varchar. The first 8 characters are of the format: YYYYMMDD (ie. 20081205FileInfo.txt). I know that SQL Server will accept in a SQL statement a date spelled out like: 'YYYYMMDD' if you use the single quotes. The string is automatically converted into date/time. I want to take advantage of this by getting the first 8 characters out of this string in the 'FileName' field and include that in my update statement to update the PostDate field of the myTransactions table (note: 'PostDate' is dataTyped as date/time).