Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update a table with data from a select

Status
Not open for further replies.

Brandan34

Programmer
Oct 1, 2008
4
US
I have a table that has some poorly formed data. A person can read it and understand it well enough to know what the person entering the data meant. Any program I make has lots of problems with it so I need to fix this data.

I can create a select statement that uses the poorly formed data and with a concatenate and data from other columns in the same record is able to display the data as it should have been entered.

My question, how do I take data from a select statement and use it in an update statement? Or is there a different approach that would be easier to solve this problem? I should only need to do this once so a workaround that may not be standard would be fine.

Thanks
 
A starting point:
Code:
UPDATE yourTable
SET PoorlyFormedColumn = PoorlyFormedColumn || OtherColumn
WHERE PoorlyFormedColumn <> PoorlyFormedColumn || OtherColumn

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I was trying what you posted and several variations, when I did not have any luck getting them to work with my database(SQLite3) I posted, thinking that I was overlooking something simple.

What I came up with that worked is just have the select display what I need as SQL, copy it to a batch file then run the batch file with the database. It is not pretty, but it does solve my problem and with luck I will not have to do this again.

Thanks for the sujection. For anyone else who has a problem like this and does not mind a workaround, this is what I came up with.

Code:
select "update DataBaseName set PoorlyFormedColumn='" || PoorlyFormedColumn || OtherColumn || "' where rowID=" ||rowID from DataBaseName WHERE PoorlyFormedColumn <> PoorlyFormedColumn || OtherColumn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top