Re: Advanced? Parsing Methods

From: Albert D. Kallal (PleaseNOOOsPAMMkallal_at_msn.com)
Date: 10/07/04


Date: Wed, 6 Oct 2004 18:17:37 -0600


"MikeC" <anonymous@discussions.microsoft.com> wrote in message
news:Gk_8d.24966$QJ3.877@newssvr21.news.prodigy.com...

>I have developed a fully functioning sub that parses data from a CSV file
>and writes new records to a table in a SQL Server 2000 database.
>
> I am currently in the process of optimizing my code and was wondering if
> there is a more efficient/advanced way to parse the data before I pass it
> to my SQL string variable, called strSQL.

The above is a good question.Fact is we often deal with comma data, space
data, or all kinds of delimiters. Every developer over time will likely
build up a nice library of code. Prior to a2000, I wrote a function called

   strDfield("text", "delimiter", which delimiter)

of course, you can do the same thing with split() command

So, to pass two values to a form via open args, the forms on-load event can
parse out the two values like:

parms1 = split(me.OpenArgs,"~")(0)
parms2 = split(me.OpenArgs,"~")(1)

Of couse, the above me.Open args would be some text like
"#11/11/2004#~StartDate"
So, parms1 would be a date, and the parms2 would be the field name for
example.

>
> Would it be faster to use the Split() function to parse each line (using a
> comma delimiter) and pass the parsed data to an array? Some other
> approach? If so, what would be the most efficient way to do this?

I don't know if you have a performance problem here do you? Certainly
building up your own spilt routines in place of whole bunch of mids, and
instrs will make your life a zillion times easer. So, I am certainly with
you in terms of the need for developers to have a nice grab bag of routines
that parse out strings..since this is common requirement.

So, are you looking to make the coding job easer, or are you looking to
increase the performance of what you got now working?

If you are looking at a performance issued, then yes..split is going to be
quite fast....

So, while you can use:

strSomevVale = split("one,two,three,four")(1)

The above would thus results in strSomeValue being now = two

So, for handy dandy reductions of code, the split is great, and you don't
have to put the results into an array.

However, since you need to repeat "hit" the string and pull out values, then
no need to run the split over and over again..is there?

Also, looking at what you got...you likely could have used transfer text to
a temp table..and then transfer that to the server....

As for performance increase?, I would use a recordset in place of executing
inserts each time...

 would certainly go:

dim vBuf as varient
dim rstTable as new ADODB.Recordset

   rstTable.Open "w$fxrateload", cnn1

vBuf = split(strSingeLine,",")

You now have a variant array full of the delimited data

     rstTable.AddNew
     rstTable!BatchNumber = v(0)
     rstTable!from_currentcy = v(1)
     rstTable!to_currency = v(2)
     rstTable!exectuionstamp = now()
..etc. etc. etc.
     rstTable.Update

You can see the above recordset is MUCH cleaner then the sql stamntet.
Futher, it will run about 100 times faster also....

-- 
Albert D. Kallal   (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com
http://www.attcanada.net/~kallal.msn


Relevant Pages

  • Re: Advanced? Parsing Methods
    ... >>and writes new records to a table in a SQL Server 2000 database. ... >> Would it be faster to use the Splitfunction to parse each line (using ... >> a comma delimiter) and pass the parsed data to an array? ... that I can select a specific item within the array. ...
    (microsoft.public.access.modulesdaovba)
  • Re: SQL - SELECT INTO making temporary Excel table
    ... I was mixing the ForPro SQL with Jet; ... He can't further query RecordSet using the SELECT statement, ... > having an Array keyword (and how does the array move from SQL engine to ...
    (microsoft.public.excel.programming)
  • Re: Using values in an array to assign a recordset variable
    ... I don't want to load the array with values from my recordset. ... up the next value..assign it to the variable, inset into the SAME sql ... depending upon whether the boolean value, in my variable, is True or false. ...
    (microsoft.public.vb.database.ado)
  • Re: REPLACE in SQL function against text files
    ... In that case you could replace in the recordset or do rs.GetRows and replace in the array and then dump that array in Excel. ... Possibly there is a way to do this in SQL and maybe somebody else will tell you. ...
    (microsoft.public.excel.programming)
  • Re: Run SQL on Recordsets?
    ... array. ... About the closest you can get is to use the Filter method of a recordset. ... > Is it somehow possible to run SQL on Recordsets? ...
    (microsoft.public.data.ado)