I have a proc in MS SQL that behaves differently depending on which server the proc is run.
Proc B calls proc A which returns a sorted a table. Proc B takes the top 1 record from the sorted table.
On our production server, the sort is preserved and we get the expected record.
In our test environment (basically a clone of production) the sort is lost and we appear to get a random record.
Here is an excerpt of the code from the calling procedure:
SELECT TOP 1 variable1, variable2
FROM [dbo].udf_MyUserDefinedFunction()
Please note:
1. I have checked settings on both servers, also SQL settings, and see no significant differences. Both production and test are running (SQL 2012) . The compatibility level of Test is 110. In theory, production is the same, but I am unable to confirm this.
2. The obvious solution of enforcing the sort in the calling procedure is not available to me. I do not have access to the code. At this time, I am only being asked to explain why our test and production environments are getting a different result.
Proc B calls proc A which returns a sorted a table. Proc B takes the top 1 record from the sorted table.
On our production server, the sort is preserved and we get the expected record.
In our test environment (basically a clone of production) the sort is lost and we appear to get a random record.
Here is an excerpt of the code from the calling procedure:
SELECT TOP 1 variable1, variable2
FROM [dbo].udf_MyUserDefinedFunction()
Please note:
1. I have checked settings on both servers, also SQL settings, and see no significant differences. Both production and test are running (SQL 2012) . The compatibility level of Test is 110. In theory, production is the same, but I am unable to confirm this.
2. The obvious solution of enforcing the sort in the calling procedure is not available to me. I do not have access to the code. At this time, I am only being asked to explain why our test and production environments are getting a different result.