好的,这是我为你准备的最好的你仍然需要改变 1 或 2 件事
假设:
create table GroupList (GroupName varchar(50),
LiveConnectEmailClosure varchar(50),
EnableSharing varchar(50),
GroupDescription varchar(50));
insert into GroupList values('GroupName1','YES','True','SomeDescrition');
insert into GroupList values('GroupName1','YES','True','SomeDescrition');
insert into GroupList values('GroupName1','NO','False','SomeDescrition');
insert into GroupList values('GroupName2','YES','True','SomeDescrition');
insert into GroupList values('GroupName2','YES','False','SomeDescrition');
insert into GroupList values('GroupName3','NO','True','SomeDescrition');
insert into GroupList values('GroupName3','NO','False','SomeDescrition');
insert into GroupList values('GroupName4','NO','True','SomeDescrition');
insert into GroupList values('GroupName4','NO','True','SomeDescrition');
insert into GroupList values('GroupName4','YES','False','SomeDescrition');
然后
SELECT *
FROM GroupList
WHERE
CASE @SortColumn
WHEN 'GroupName ASC' THEN GroupName END ASC,
WHEN 'GroupName DESC' THEN GroupName END DESC,
WHEN 'LCC ASC' THEN LiveConnectEmailClosure END ASC,
WHEN 'LCC DESC' THEN LiveConnectEmailClosure END DESC,
WHEN 'ES ASC' THEN EnableSharing END ASC,
WHEN 'ES DESC' THEN EnableSharing END DESC,
WHEN 'Description ASC' THEN GroupDescription END ASC,
WHEN 'Description DESC' THEN GroupDescription END DESC
ELSE GroupName END ASC;
这是我能用 oa T-sql 编辑器做的最好的希望这有帮助
除此之外:请看Florian Reischl 的回答
SELECT
CASE
WHEN xyz.something = 1 THEN 'SOMETEXT'
WHEN xyz.somethingelse = 1 THEN 'SOMEOTHERTEXT'
WHEN xyz.somethingelseagain = 2 THEN 'SOMEOTHERTEXTGOESHERE'
ELSE 'SOMETHING UNKNOWN'
END AS ColumnName;