tsql的奇特语法

也许是离开t-sql太久了,突然发现很多t-sql的奇特语法

用一句sql解决多种排序:

declare  @flag int=0;

SELECT C1, C2

FROM T ORDER BY

   CASE WHEN @flag = 1 THEN C1 END ASC,

   CASE WHEN @flag = 0 THEN C1 END DESC

插入N行数据(省得每行数据写一遍insert ... values了):

insert into t (C1, C2)

values

(1,1),

(2,2),

...

(N-1,N-1),

(N,N)

 

你可能感兴趣的:(sql)