SDU Tools: SQL Server Type

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. A request that I had a while back was to have a function that returned what type of SQL Server the code was being executed on. So we added the SQLServerType function.
It takes no parameters.
As this is an enumerated value, it’s just a CASE statement.
Find out more
You can see it in action in the main image above, and in the video here. The full current version of the code is also shown below:
You can use our tools as a set or as a great example of how to write functions like these.
Access to SDU Tools is one of the benefits of being an SDU Insider, along with access to our other free tools and eBooks. Please just visit here for more info:
http://sdutools.sqldownunder.com
Latest version of the code
Note: the code might wrap when displayed below.
CREATE FUNCTION SDU_Tools.SQLServerType()
RETURNS nvarchar(40)
AS
BEGIN
-- Function: Returns the type of SQL Server for the current session
-- Parameters: Nil
-- Action: Returns the type of SQL Server for the current session
-- Return: nvarchar(40)
-- Refer to this video: https://youtu.be/tASWb2eN-8w
--
-- Test examples:
/*
SELECT SDU_Tools.SQLServerType();
*/
RETURN CASE SERVERPROPERTY('EngineEdition')
WHEN 1 THEN N'Desktop'
WHEN 2 THEN N'Standard'
WHEN 3 THEN N'Enterprise'
WHEN 4 THEN N'Express'
WHEN 5 THEN N'Azure SQL Database'
WHEN 6 THEN N'Azure Synapse Analytics'
WHEN 8 THEN N'Azure SQL Managed Instance'
WHEN 9 THEN N'Azure SQL Edge'
WHEN 11 THEN N'Azure Synapse Serverless Pool'
ELSE N'Unknown'
END;
END;
2025-02-19