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:
In reply to Re: Win32::ODBC query error
by radiantmatrix
in thread Win32::ODBC query error
by nicpon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |