假设我有两个数字,@ n1,@ n2,我想在Max(@ n1,@ n2)这样的简单表达式中得到更大的数字。如何编写T-SQL的表达式?
答案 0 :(得分:4)
DECLARE
@n1 INT = 2,
@n2 INT = 3
SELECT MAX(n) FROM (VALUES(@n1), (@n2)) t(n)
答案 1 :(得分:3)
CASE WHEN @n1 > @n2 THEN @n1 ELSE @n2 END
答案 2 :(得分:-2)
DECLARE @a int = 45, @b int = 40;
SELECT IIF ( @a > @b, @a, @b ) AS Result;