I'm having a little problem on how to execute two queries one after the other.
In my Powershell script I'm adding records in a loop (which works perfectly fine). Outside the LOOP I execute a query to Delete "x" number of records based on the TIMESTAMP (which is working) but after that one is executed I want to run a query to display the number of ROWS that have been affected and display it. Below is my code.
Thanks in advance!
### =============================================================
### Deleting every record that is 30 minutes old
### =============================================================
$command = $connection.CreateCommand();
$command.Connection = $connection;
$command.CommandText = "DELETE FROM workstation_userlogged
WHERE lastupdate < (NOW() - INTERVAL 30 MINUTE)";
$records_deleted = "SELECT row_count()"; #count number of rows affected by the delete query
$command.CommandText = "$records_deleted";
TRY{
$command.ExecuteNonQuery() | out-null;
Write-Host "Successfully deleted $records_deleted records from the Database" -ForegroundColor Green;
}
CATCH{
Write-Host "Caught the exception" -ForegroundColor Red;
Write-Host "$_" -ForegroundColor Red;
}
COUNT()with your where condition before deleting the rows?