I have a query that generally goes
SELECT *
FROM BILL_HISTORY a
JOIN
(
Sel *
from SERVICE_INFO
Qualify Row_Number() OVER (PARTITION BY Service, Product_Code1,
Product_Code2 ORDER BY Effective_Date1 DESC, Effective_Date2 DESC) = 1
) b
ON a.SERVICE = b.SERVICE
The expected result set is 6 months of past invoices with additional columns from SERVICE_INFO. If I run this query manually with a WHERE clause on a specific service ID, I receive the expected result. However, if I run the same query wrapped in a CREATE VOLATILE TABLE ... AS (SELECT * ... ) then when I query the same service ID, I only receive the most recent invoice ID for that service.
Any reasons why this may occur? Same result if I create the table as perm or volatile. Real head-scratcher...
EDIT: show the general sub-query that was made on the JOIN as this seemed to be related to the cause of the problem.