Update begins: I realized that you'd also save yourself some headaches if you just convert this entire process to a single SQL statement, and let SQL Server do the code-work.

UPDATE category SET chrCat_Full_Name=UPPER(LEFT(chrCat_Full_Name,1)) +LOWER(RIGHT(chrCat_Full_Name,DATALENGTH(chrCat_Full_Name)+1))

That's untested, but should do the job, no Perl required.:update Ends

You'll save yourself a lot of headaches talking to MSSQL server (as you mentioned you are, in one of the replies above) via ODBC using DBI with the DBD::ODBC module. That setup allows you to do the above with placeholders, which are far easier to read and debug than what you've got above.

use DBI; require DBD::ODBC; ## will be done auto, but doesn't hurt to check. my $db = DBI->connect($dsn,'','',{RaiseError=>1}); my $db2 = DBI->connect($dsn2,'','',{RaiseError=>1}); my $sql ="SELECT * FROM category"; my $sth = $db->prepare($sql); $sth->execute(); ## ? is a placeholder that will be auto-quoted later! my $sql2 = 'update category set chrCat_Full_Name=? where chrCategory_C +ode=?'; ## now we get the DBI ready to execute that statement many times with +different placeholders my $sth2 = $db2->prepare($sql2); while (my $data = $sth->fetchrow_hashref()) { ## the parameters passed will be quoted and substituted ## for the placeholders in order $sth2->execute( ucfirst( lc($data->{'chrCat_Full_Name'}) ), $data->{'chrCategory_Code'} ); ## this won't show your parameters, to do that you can trace ## or just explicitly print them. print "$sql2 $data->{'chrCat_Full_Name'}\n"; } $db->disconnect; $db2->disconnect;

The {RaiseError=>1} in the call to connect() causes the app to die() with the error if one is encountered during any DB operation. You'll probably want to handle those eventually.

Updates:

<-radiant.matrix->
Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law

In reply to Re: Win32::ODBC query error by radiantmatrix
in thread Win32::ODBC query error by nicpon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.