Jump to content
Fivewin Brasil

INSERT INTO/UPDATE


mkyx

Recommended Posts

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

 

 

 

 

 

 

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...