设置变量时的SQL情况

时间:2013-04-10 20:02:15

标签: sql sql-server-2008-r2 case-when

我试图在块

的情况下设置2声明变量

这是我的代码:

DECLARE @like bit,@dislike bit
if exists
( select * 
    ,@like = (CASE WHEN likeordislike = 1 THEN 'true' ELSE 'false' END)
    ,@dislike=(CASE WHEN likeordislike = 0 THEN 'true' ELSE 'false' END)
  from likeordislike
)

但是当我执行查询抛出错误时:

  

Msg 102,Level 15,State 1,Line 4
  '='附近的语法不正确。

一切都好吗?无法理解

1 个答案:

答案 0 :(得分:1)

if (select count(*) from likeordislike where user = @user and comment_id = @comment_id) = 0
begin
  insert into likeordislike etc
end 
else
  update likeordislike etc
end