mkyx Posted November 22, 2019 Report Share Posted November 22, 2019 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. Quote Link to comment Share on other sites More sharing options...
zekasan Posted December 6, 2019 Report Share Posted December 6, 2019 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" aferra and Luiz Fernando 2 Quote Link to comment Share on other sites More sharing options...
alex2002 Posted December 9, 2019 Report Share Posted December 9, 2019 Olá. Tente: APCODE:="insert into historicos (codigo,descricao,ent_sai) value ('TRANSF-ENT','TRANSFERÊNCIAS-ENTRADAS','E') where (select 'tem' from historicos where codigo='TRANSF-ENT' limit 1 ) is null ; OSQL:EXEC(APCODE ) Creio que funcionará. Um abraço, Alexandre Pereira Luiz Fernando 1 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.