我正在尝试在SQL Express中创建一个变量,问题是我希望默认值来自查询而我无法弄明白。这就是我想要做的事情:
DECLARE @myVar int = select max(MYCOLUMN) from MYTABLE;
select (someColumn / @myVar) as newCol
from MYTABLE
答案 0 :(得分:0)
DECLARE @myVar int = 0;
select @myVar = max(MYCOLUMN)
from MYTABLE;
select (someColumn / @myVar) as newCol
from MYTABLE
答案 1 :(得分:0)
您真正缺少的是围绕您尝试设置为默认值的括号。
DECLARE @myVar INT = (SELECT MAX(MYCOLUMN) FROM MYTABLE)
SELECT (someColumn / @myVar) AS newCol
FROM MYTABLE