Instead of using the series of CASE expressions, create a table like shown below and insert the mappings into that table. You can create the insert statements easily in Excel or an editor that has regular expression capabilities by copying the text from your function and editing.CREATE TABLE dbo.EventCodeToStringMap
(
EventCode NVARCHAR(256) NOT NULL PRIMARY KEY,
EventString NVARCHAR(256) NOT NULL
);
INSERT INTO dbo.EventCodeToStringMap VALUES
('EV_TYPE_VCP_SYSTEM_MONITOR_DEBUG', 'SYSTEM MONITOR DEBUG');
-- and so on for all the pairs
Now that you have the table, returning the values is easy - a simple select like shown belowSELECT EventString FROM dbo.EventCodeToStringMap
WHERE EventCode = @string;
In fact, I would suggest that you don't even create a function to do this. Join to your new table where you need to do the mapping. A function call is more expensive - because it gets called for each row in your query.
Also, as a best practice, if you don't need NVARCHAR(MAX), use NVARCHAR with a smaller length.