Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal...estou com uma dúvida em relação a um update. Estou fazendo assim:
String sql="UPDATE investigambulat SET codLocPreNat='"+Integer.parseInt(dadosInvestigAmbulat[1])+"',preNatAltoRisco='"+dadosInvestigAmbulat[2]+
"',localPreNatRisco='"+dadosInvestigAmbulat[3]+"' WHERE codInvestig=(SELECT codInvestig FROM "+
"investigacao A,investigambulat B WHERE A.numDO='"+dadosInvestigAmbulat[0]+"')";
Minhas tabelas estão assim:
INVESTIGAMBULAT INVESTIGACAO
codInvestigAmbul codInvestig
codInvestig dtInvestig
codLocalInvestig nomeInvestig
codLocPreNat funcaoInvestig
preNatAltoRisco numDO
localPreNatRisco statusInvest
natRetornAmbulat codDS
Estou obtendo o erro: "Column 'codInvestig' in field list is ambiguous". Como resolver isto ?
Grato, Fernando...já auxiliou. Estou tentando com o código abaixo.
Mas ele está alterando múltiplas ocorrencias...quero somente onde o codInvestig seja 99, por exemplo.
String sql="UPDATE investigambulat SET codLocPreNat='"+Integer.parseInt(dadosInvestigAmbulat[1])+"',preNatAltoRisco='"+dadosInvestigAmbulat[2]+
"',localPreNatRisco='"+dadosInvestigAmbulat[3]+"' WHERE investigambulat.codInvestig=(SELECT investigacao.codInvestig FROM "+
"investigacao WHERE numDO='"+dadosInvestigAmbulat[0]+"' AND investigacao.codInvestig=investigambulat.codInvestig)";então.. não entendi muito bem o q você está precisando fazer,
mas, basicamente: se você quer alterar a tabela onde codinvest é chave primária,
ok, o registro será único.. ai não tem erro, você irá alterar apenas 1 registro..
mas se quer alterar uma tabela onde essa coluna não é unica..
a alteração vai rolar em todos os registros que tiverem essa coluna = a 1 valor..
mas, se ainda não resolveu, retorne e por gentileza explique melhor, ok?
mensagem bem clara.. duas colunas com o mesmo nome...
defina a coluna com o nome da tabela;
exemplo:
WHERE tabela1.codInvestig=(SELECT tabela2.codInvestig ...