I am successful in connecting to a remote SQL database and printing information from tables. I need some assistance on how to change the value(s) of a column after I retrieve the data. For example, SQL may have the value of ‘0’ or ‘1’ for false or true. I need to print/write false/true in lieu of 0 or 1.
The following script works and prints the actual values from a SQL table. How would I change the ProductID from ‘1’ to another value like ‘True’ and then print? I have used the Northwind database as an example for the functionality that I need to know how to implement for a different DB. Thanks!
use DBI;
$data_source = "driver={SQL Server};Server={192.168.6.100};database={Northwind};UID={sa};PWD={password}";
$dbh = DBI->connect("dbi:ODBC:$data_source") or die "$DBI::errstr";
$sql = qq/
SELECT OrderID, ProductID, ProductName
FROM "Order Details Extended"
WHERE ProductName = 'Chai'
/;
$sth = $dbh->prepare( $sql );
$sth->execute;
while (@row = $sth->fetchrow_array()) {
print "$row[0] $row[1] $row[2]\n";
}
exit(0);
The following script works and prints the actual values from a SQL table. How would I change the ProductID from ‘1’ to another value like ‘True’ and then print? I have used the Northwind database as an example for the functionality that I need to know how to implement for a different DB. Thanks!
use DBI;
$data_source = "driver={SQL Server};Server={192.168.6.100};database={Northwind};UID={sa};PWD={password}";
$dbh = DBI->connect("dbi:ODBC:$data_source") or die "$DBI::errstr";
$sql = qq/
SELECT OrderID, ProductID, ProductName
FROM "Order Details Extended"
WHERE ProductName = 'Chai'
/;
$sth = $dbh->prepare( $sql );
$sth->execute;
while (@row = $sth->fetchrow_array()) {
print "$row[0] $row[1] $row[2]\n";
}
exit(0);