VBscripts generates SQL update stmt from txt

Greeting,

I need to generate a update stmt from a txt file which contains multiple columns(the white space between columns are unkown). Below is what I have but only populate 1st column in the sql file.

strInput = "ALL.txt"
strOutput = "UpdateALL.SQL"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile(strInput, 1, False)
Set objOutput = objFSO.CreateTextFile(strOutput, True)
While Not objInput.AtEndOfStream
   strLine = objInput.ReadLine
   arrNames = Split(strLine, " ")
   strStatement = "Update " & Trim(arrNames(0)) & " SET "&Trim(arrNames(1))&"='"&Trim(arrNames(3))&"' WHERE "&Trim(arrNames(1))&"='"&Trim(arrNames(2))&"';"
   objOutput.WriteLine strStatement
Wend
objInput.Close
objOutput.Close
WScript.Echo "Done"

Open in new window

Please provide code.

Thanks in advance.
mrongAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
Please provide a sample of the input file.

~bp
0
mrongAuthor Commented:
Below is my own solution. thanks.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInput = objFSO.OpenTextFile(strInput, 1, False)
Set objOutput = objFSO.CreateTextFile(strOutput, True)
While Not objInput.AtEndOfStream
   strLine = objInput.ReadLine
   Do While Instr(strLine, "  ") > 0
      strLine = Replace(strLine, "  ", " ")
   Loop
   arrNames = Split(strLine, " ")
   strColumn1 = arrNames(0)
   strColumn2 = arrNames(1) 
   strColumn3 = arrNames(2) 
   strColumn4 = arrNames(3) 
   arrNames = Split(strLine, " ")
   strStatement = "Update " & Trim(strColumn1) & " SET "&Trim(strColumn2)&"='"&Trim(strColumn4)&"' WHERE "&Trim(strColumn2)&"='"&Trim(strColumn3)&"';"
			objOutput.WriteLine strStatement			
Wend

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mrongAuthor Commented:
Found own solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.