我有@myvar以下查询如何在以下查询中乘以(@myvar * -1)。
SELECT
Date,
case when Position > 0 then
Position * Mark * case when SecurityType in ('Equity','Equity Option') Then Mark * 100 else 1 end
else
0
end var,
case when Position < 0 then
Position * Mark * case when SecurityType in ('Equity','Equity Option') Then .Mark * 100 else 1 end
else
0
end (@myvar * -1),Id FROM Mytable
- 我收到错误
帮助我:)
答案 0 :(得分:1)
您在最后一次结束后错过了逗号以指定新列。如果您只是返回-1 * myvar,那么您所拥有的表达式是正确的。
SELECT
Date,
case when Position > 0 then
Position * Mark * case when SecurityType in ('Equity','Equity Option') Then Mark * 100 else 1 end
else
0
end var,
case when Position < 0 then
Position * Mark * case when SecurityType in ('Equity','Equity Option') Then Mark * 100 else 1 end
else
0
end,
(@myvar * -1) -- I'm getting error
答案 1 :(得分:1)
我只需要做
case when Position < 0 then
-1 * Position * Mark * case when SecurityType in ('Equity','Equity Option') Then Mark * 100 else 1 end**
else
0
end Myvar , -- myvar will be (-) because in above condition i multiply -1
Id
FROM mytable