Link to home
Start Free TrialLog in
Avatar of mrong
mrong

asked on

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.
Avatar of Bill Prew
Bill Prew

Please provide a sample of the input file.

~bp
ASKER CERTIFIED SOLUTION
Avatar of mrong
mrong

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrong

ASKER

Found own solution.