开发者

Tsql ordering data by specific string values

开发者 https://www.devze.com 2022-12-28 18:58 出处:网络
I have an audit table that have data for insert, update and delete 开发者_开发百科operations. I am writing a report that will display data in the order of Insert, Update and Delete. I don\'t think the

I have an audit table that have data for insert, update and delete 开发者_开发百科operations. I am writing a report that will display data in the order of Insert, Update and Delete. I don't think the order by clause will help. any help?


You can use an ORDER BY combined with a CASE clause:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号