I have a stored procedure. In it, there is an inline select that UNIONs several tables. If I highlight the code within the SP and execute it, it runs fine and returns 10 million rows.
If I copy the highlighted code to a new query window and execute that, it returns only about 55000 rows (the same number of rows that the first select in the inline view returns).
Can someone explain what is going on?
SELECT COUNT(*) FROM
(
SELECT SequenceId, comment_text [Text], comment_end_date
FROM dart_comment
UNION
SELECT SequenceId, adj_comment [Text], report_date comment_end_date
FROM dart_labor_detail
WHERE adj_user_id != null AND adj_user_id != 'None'
UNION
SELECT SequenceId, adj_comment [Text], report_date comment_end_date
FROM dart_suspend_detail
WHERE adj_id != null AND adj_id != 'None'
UNION
SELECT SequenceId, adj_comment [Text], report_date comment_end_date
FROM dart_labor_history
WHERE adj_user_id != null AND adj_user_id != 'None'
UNION
SELECT SequenceId, adj_comment [Text], report_date comment_end_date
FROM dart_suspend_history
WHERE adj_id != null AND adj_id != 'None'
)
The only difference is highlighting the code inside the SP, and copying (and highlighting) the code in a new query window (tied to the same database as the SP).