I have a table that contains the following columns:
|DatabaseName|AccountIndexDue|AccountIndexFrom|
|THX|293|8284|
|FRM|280|9238|
|MKZ|2094|72364|
I'd like to create either a stored procedure or sql view that basically looks something like this:
SELECT 'THX' as [Entity Id] * From THX..GL20000 WHERE AccountIndex in (293, 8284) UNION ALL
SELECT 'FRM' as [Entity Id] * From FRM..GL20000 WHERE AccountIndex in (280, 9238) UNION ALL
SELECT 'MKZ' as [Entity Id] * From MKZ..GL20000 WHERE AccountIndex in (2094, 72364)
I'm putting the result set into a table so ideally a Cursor Loop statement would likely work but I'm not exactly sure how to write something like that.
Suggestions?