Tsql sorts data by specific string values

I have an audit table that has data for insert, update, and delete operations. I am writing a report that will display data in insert, update and delete order. I don’t think order suggestion will help. any help?

+5
source share
1 answer

You can use ORDER BY in combination with the CASE clause :

SELECT *
FROM auditlog
ORDER BY CASE operation_type
    WHEN 'Insert' THEN 1
    WHEN 'Update' THEN 2
    WHEN 'Delete' THEN 3
END
+10
source

All Articles