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...

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 9 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 9 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004