I have an existing stored procedure that is being used to talk to another service. This other service can handle a max of 200 requests every 5 minutes, so the stored procedure is set to a maximum of 200 rows.
SELECT TOP 200
column1 as 'MESSAGE_A'
, column2 as 'MESSAGE_B'
, column3 as 'MESSAGE_C'
, CAST(request as xml)
FROM [table]
ORDER BY [priority] ASC, column1 ASC
FOR XML PATH ('result_xml'), TYPE, ROOT ('requests')
The problem is that, while the procedure runs automatically every 5 minutes it can also be run manually (because clients).
In the event that a manual execution tips the requests over 200, the third party gets borked and the process crashes.
How can I add a check so that it will select a maximum of 200 rows in a 5 minute time frame?