When using a basic cursor to iterate through names of databases on which to perform actions (log backups in this case) the query used to generate the cursor returns all expected rows but the cursor iteration does not. When running the SELECT statement alone there are 5 database names returned; when iterating through the cursor only the first and last are returned. If the "STATIC" keyword is added to the cursor declaration then all 5 results are returned. If the LEFT OUTER JOIN portion of the query is removed then the query returns all expected values. This isn't a viable workaround for us since we need to execute this job on all servers participating in an Availability Group setup and need to only execute the commands against databases being hosted on the server.
Operating System Language
Steps to Reproduce