mkyx Posted August 20, 2017 Report Share Posted August 20, 2017 Boa tarde, fivewinners, Alguém sabe como fazer no mysql, num só comando um INSERT ou um UPDATE dependendo de uma condição? Exemplo: preciso incluir a ficha de um cliente, se essa ficha não existir, eu executo um INSERT, caso contrário executo um UPDATE. Agora, estou trabalhando com a rotina abaixo, e não achei muito inteligente, pesquisando na net, só achei comandos básico. e_esta:=.F. if select("ARQ_BANCOS")=0 e_esta:=.T. ELSE SELECT ARQ_BANCOS endif cSqlQ:="SELECT * FROM BANCOS WHERE CODIGO="+CHR(34)+STRZERO(NB,4)+CHR(34)+";" dbUseArea(e_esta, "SQLRDD", cSqlQ, 'ARQ_BANCOS') IF ARQ_SALDOS->(EOF()) APCODE:="INSERT INTO BANCOS (CODIGO,NOME) VALUE ("+CHR(34)+STRZERO(NB,4)+CHR(34)+","+CHR(34)+ALLTRIM(NO_B)+CHR(34)+");" OSQL:EXEC(APCODE ) else APCODE:="UPDATE BANCOS SET NOME="+CHR(34)+ALLTRIM(NO_B)+CHR(34)+" WHERE CODIGO="+CHR(34)+STRZERO(NB,4)+CHR(34)+";" OSQL:EXEC(APCODE ) endif Muito grato. Pompeo Guaratinguetá - SP Quote Link to comment Share on other sites More sharing options...
evandro Posted August 20, 2017 Report Share Posted August 20, 2017 Olá, Utilize o comando REPLACE que faz exatamente o que você precisa. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.