I have a basic question regarding the streamlining of VBScript/SQL code. I have a working script that pulls data from one table, parses it by delimiter '|', and reinserts it to a second 254 column table. In doing so, I explicitly wrote out each field for the insert, and each part of the array for values. Obviously, this isn't very efficient. To streamline this, I've been trying to loop through the array, insert the resulting row, and move to the next, like so:
'assume declaration of recordset, SQL connection, pull from first table, ect.
if recordset.EOF then
wscript.echo "No new records found."
else
Do While NOT Recordset.EOF
dump = recordset("data")
if dump <> "" then
dump = Replace(dump,"'","")
cleanup=split(field,"|")
if instr(cleanup(0),"RECORD") then
for i = 1 to 254
cleanup(i)= cleanup(i) & "','"
i= i + 1
next
end if
strRecsql="INSERT INTO records_fields VALUES ('" & cleanup & "')"
connection.execute strRecsql
Now, when I explicitly stated all the fields and values, I ironed out all the datatype mismatch issues. Now that I'm looping through, I'm getting the datatype mismatch error, which I assume (always dangerous) means the script is reaching the insert point and failing.
My long code included things like cleanup(1) & "," & cleanup(2) & "," ''and so on Obviously, I'm doing something wrong in trying to loop through-- I'm just stumped because of the datatype mismatch.
Any insight into this issue would be very much appreciated. I'd love to have a code that works AND is efficient, and I'm just curious in general about datatype exchange between VBScript and SQL. I've found some excellent resources on the variant type and SQL types in general, but nothing that addresses the exchange.
Sample dump value:
"RECORD|2-10-15 00:00:00|SMITH|JOHN|+14.59|STAPLES| | | | | |AE15679|j2700| | |Office supplies| | |"
cleanupvariable is an array. You cannot simply concatenate an array with a string. You need to flatren the array back to a string using join() function. - Shadowdumpvalue? - Susilodumpvalue looks like this: "RECORD|2-10-15 00:00:00|SMITH|JOHN|+14.59|STAPLES| | | | | |AE15679|j2700| | |Office supplies| | |" ... and so on, for 254 columns. A lot of them are empty, which didn't actually give me a problem when I was writing out the entire array input by hand. - atomickiwi