Reputation: 55
I need a script to get some values from a .csv file and write the rows into a database: my code is as follow and it works very well, but I need the rows inserted in certain tables, depending on some triggers.
set objconn = Server.CreateObject("ADODB.Connection")
objconn.Provider="Microsoft.Jet.OLEDB.4.0"
objconn.ConnectionTimeout = 15
objconn.CommandTimeout = 30
objconn.Open ConString
csv_to_read="ordini.csv"
set fso = createobject("scripting.filesystemobject")
set act = fso.opentextfile(server.mappath(csv_to_read),1)
dim sline
dim sSeg
Do Until act.AtEndOfStream
sline=act.readline
sline = Replace(sline,"""","")
sSeg=split(sline,",")
dim strsql
if sSeg(4) = "1" then
strsql="INSERT INTO tbl_test (id_order, client, code, description, qty, price)"
strsql=strsql & "VALUES('"&sSeg(0)&"', '"&sSeg(1)&"', '"&sSeg(2)&"', '"&sSeg(3)&"', '"&sSeg(4)&"', '"&sSeg(5)&"')"
end if
objconn.execute strsql
loop
act.close
set act=nothing
objconn.close
set objconn=nothing
What I want is inserting the rows in different tables, depending on the client value. So, if the client = 1, I need the result to be inserted in the tbl_test2 table, otherwise everything can go to the regular tbl_test. I know it can't be made, but I really can't get how...
Upvotes: 0
Views: 35
Reputation: 9298
if sSeg(4) = "1" then
strsql = "INSERT INTO tbl_test2 ......... "
else
strsql="INSERT INTO tbl_test (id_order, client, code, description, qty, price)"
strsql=strsql & "VALUES('"&sSeg(0)&"', '"&sSeg(1)&"', '"&sSeg(2)&"', '"&sSeg(3)&"', '"&sSeg(4)&"', '"&sSeg(5)&"')"
end if
if that doesnt work try removing quotes for the value like this:
if sSeg(4) = 1 then
Upvotes: 1