How do i muliply any declare variable by -1 in 'case' statement?
I have @myvar with following query how do i multiply (@myvar * -1) in following query.
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
-- I'm g开发者_运维技巧etting error
help me :)
You're missing a comma after your last end to specify a new column. If you're just returning -1 * myvar, then the expression you have is correct.
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
hey all i got the answer
I just need to do
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
精彩评论