SQL过程中的自定义顺序

时间:2017-04-28 10:25:20

标签: sql sql-server

目前正在进入

G8984 - Carrying, Moving & Handling Objects - Current (CJ) 20 – 39% Impaired.
G8985 - Carrying, Moving & Handling Objects - Projected (CI) 1 – 19% Impaired.
G8985 - Carrying, Moving & Handling Objects - Projected (CI) 1 – 19% Impaired.
G8986 - Carrying, Moving & Handling Objects - Discharge (CL) 60 – 79% Impaired.

要求是:

G8986 - Carrying, Moving & Handling Objects - Discharge (CL) 60 – 79% Impaired.
G8984 - Carrying, Moving & Handling Objects - Current (CJ) 20 – 39% Impaired.
G8985 - Carrying, Moving & Handling Objects - Projected (CI) 1 – 19% Impaired.
G8985 - Carrying, Moving & Handling Objects - Projected (CI) 1 – 19% Impaired.

我需要订购 需要先放电,然后是电流,然后是预计

我使用以下代码创建此字符串:

,(LT.[Code] + ' - ' + LFLC.[Description] + ' - ' + LFLT.[Description] + ' (' + LM.[Code] + ') ' + LM.[ShortName]) AS [Description]

表LFLT是:

enter image description here

1 个答案:

答案 0 :(得分:0)

试试这个:

SELECT ..., CASE WHEN LFLT.ID = 3 THEN 0 ELSE LFLT.ID END AS OrderIndex
FROM ...
ORDER BY OrderIndex