开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜