troubleshooting Question

Quick help with a simple SQL Update Statement

Avatar of David L. Hansen
David L. HansenFlag for United States of America asked on
Microsoft SQL ServerMicrosoft SQL Server 2005
9 Comments1 Solution517 ViewsLast Modified:
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).

Please help...

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros