if exists(select * from t_CompanySumMoney where f_id='a') then
  update t_CompanySumMoney set f_companyMoney=f_companyMoney+ 5.0 where f_id='a';
else
insert t_CompanySumMoney values('a',3);
end if

解决方案 »

  1.   

    你在什么环境下?
    mysql> ?
    == 思想重于技巧 ==
      

  2.   

    if   exists(select   *   from   t_CompanySumMoney   where   f_id='a')   then 
        update   t_CompanySumMoney   set   f_companyMoney=f_companyMoney+   5.0   where   f_id='a'; 
    else 
    insert   t_CompanySumMoney   values('a',3); 
    end   if=====================
    应该是 insert into吧,LZ
      

  3.   

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if exists(select * from t_CompanySumMoney where f_id='a') then
      update t_Compa' at line 1 
      

  4.   

    什么数据库?
    mySQL 
    == 思想重于技巧 ==
      

  5.   

    恩,要是sql server就好办了,从sql server转mysql,公司的项目
      

  6.   

    mySQL 好像就不支持if...then...
    == 思想重于技巧 ==
      

  7.   

    IF search_condition THEN statement_list
        [ELSEIF search_condition THEN statement_list] ...
        [ELSE statement_list]
    END IFmysql手册的帮助,支持if的
      

  8.   

    mySQL   好像就不支持if...then... ----------
    肯定支持,我在存储过程用过
      

  9.   

    可以这么写
    declare iCount int default 0;
    select count(*) into iCount from   t_CompanySumMoney   where   f_id='a';
    if iCount = 0 then
    insert into  t_CompanySumMoney   values('a',3);
    else
    update t_CompanySumMoney   set   f_companyMoney=f_companyMoney+   5.0   where   f_id='a';
    end if;
      

  10.   

    报错信息我已经贴上去了#1064   -   You   have   an   error   in   your   SQL   syntax;   check   the   manual   that   corresponds   to   your   MySQL   server   version   for   the   right   syntax   to   use   near   'if   exists(select   *   from   t_CompanySumMoney   where   f_id='a')   then 
        update   t_Compa'   at   line   1 
      

  11.   

    还必须写个存储过程???
    可以多语句执行吧,再说if else应该是一条语句
      

  12.   

    不在存储过程里可能不可以了。虽然有个if函数,但是不符合楼主的这种。就算存储过程也未必可以支持if   exists,我看要把exists的值select into一个变量中,然后用if可以。mysql在功能方面毕竟难以比上sql server的
      

  13.   

    SQLSERVER的语法翻译成MYSQL的。已经结贴的有个和你问题一样的。搜索一下吧
      

  14.   

    刚刚测试了一下,5.0的mysql在存储过程中还是可以用if exists的,但是单个语句应该不支持if else语句,只有if函数
    SQLSERVER的语法翻译成MYSQL的。已经结贴的有个和你问题一样的。搜索一下
    -------------
    顺便说说,版主啊,那个csdn的搜索可是出名不能用的,还不如用百度搜出来。
      

  15.   


    select   count(*)   from   t_CompanySumMoney   where   f_id='a' into @cnt;
    if   @cnt > 0  then
        update   t_CompanySumMoney   set   f_companyMoney=f_companyMoney+   5.0   where   f_id='a';
    else
    insert   t_CompanySumMoney   values('a',3);
    end   if;
      

  16.   

    好感动,谢谢大家的热心帮助,昨天加分,提示说不让加,今天加了100分sql server的功能是很不错,据说sql server 2005更猛,mysql小巧,存取快,都这么说,呵呵