Jump to content
Fivewin Brasil

INSERT COM WHERE


mkyx

Recommended Posts

Boa tarde, pessoal

Tem como fazer uma inserção no mysql, de uma informação que ainda não esteja cadastrada, num só comando INSERT?

Exemplo:

   APCODE:="insert into historicos (codigo,descricao,ent_sai) value ('TRANSF-ENT','TRANSFERÊNCIAS-ENTRADAS','E') where not exists (select * from historicos where codigo='TRANSF-ENT');
   OSQL:EXEC(APCODE )   
 

Uso o sqlrdd, mas o comando acima nem dentro do mysql 5.5 não funciona.

 

Link to comment
Share on other sites

  • 2 weeks later...

Precisei algo parecido, caso exista eu atualizo algumas variáveis, caso contrário eu insiro os dados:

    cCmdSql:="if exists (select usuario from SSW_USUARIO where Usuario = '"+cGet01_S1+"') "+;
                "    begin "+;
                "        update ssw_usuario set "+;
                "            nome = '"+ cGet06_S1 +"',"+;
                "            senha = '"+ cGet02_S1 +"',"+;
                "            nivel = "+ str(cGet05_S1,1)+","+;
                "            email = '"+ cGetEma +"',"+;
                "            emailsenha = '"+ cGetSen +"',"+;
                "            telddd = '"+ cGetDDD +"',"+;
                "            telnr = '"+ cGetTel +"',"+;
                "            telramal = '"+ cGetRam +"'"+;
                "        where usuario = '"+cGet01_S1+"' "+;
                "    end "+;
                "else "+;
                "    begin "+;
                "        insert into ssw_usuario(filial,usuario,nome,senha,nivel,email,emailsenha,telddd,telnr,telramal) "+;
                "            values( "+;
                "            '"+RET_FILIAL_SSW(cGet04_S1)+"',"+;
                "            '"+cGet01_S1+"',"+;
                "            '"+cGet06_S1+"',"+;
                "            '"+cGet02_S1+"',"+;
                "            "+str(cGet05_S1,1)+","+;
                "            '"+cGetEma+"',"+;
                "            '"+cGetSen+"',"+;
                "            '"+cGetDDD+"',"+;
                "            '"+cGetTel+"',"+;
                "            '"+cGetRam+"')"+;
                "    end"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...