Ir para conteúdo
Fórum Script Brasil
  • 0

Iner Join


filipeflc00

Pergunta

GALERA

ESTOU COM UMA DUVIDA MEIO FACIL MAS não ESTOU LEMBRADO

ASSIM EU tenho DADOS DE UMA TABELA1 NO ACCESS

EU QUERIA FAZER UM SQL Q PEGASSE OS DADOS DA TABELA1 E GRAVASSE NA TABELA2

EU não ESTOU LEMBRANDO COMO E..

ALGUNS DE vocês SABEM ME RESPONDER isso?/

VALW GALERA

T+

Link para o comentário
Compartilhar em outros sites

9 respostass a esta questão

Posts Recomendados

  • 0
Guest - Ricardo -

O inner join seleciona tabelas que possuam algum campo semelhante entre si , neste caso o que você precisa fazer é um select comum e um insert

select campo from tabela

insert into tabela (campo) values ('"& rs("campo") &"')

qualquer dúvida poste ai

abraços

Ricardo

Link para o comentário
Compartilhar em outros sites

  • 0

você tem que fazer um select na tabela um, armazenar os dados num recordset e em seguida fazer um insert na tabela 2 com os dados do recordset.

sql = "select * fr....."

Set Rs = Conn.Execute(sql)

sql = "insert into...."

Conn.Execute(sql)

abraços

Link para o comentário
Compartilhar em outros sites

  • 0

olha so galare q eu fiz...

[ASP]

cdnf  = Request.QueryString("cdnf")

ObjConn.Open conex
strSq3 = "select * from t_venda where cd_nf = "&cdnf
Set ObjRs = objConn.Execute(strSq3)

cd = ObjRs("cd_nf")
cd_func = ObjRs("cd_vend")
dt_ma = ObjRs("dt_emi")
data = ObjRs("dt_lac")
cd_ma = ObjRs("cd_prod")
nm_ma = ObjRs("nm_prod")
qtd_ma = ObjRs("quant")




strSq0 = "select * from t_uni where cod = "&cd_ma
Set ObjRs = objConn.Execute(strSq0)




quantidade_pedida = qtd_ma
saldo_em_estoque = Cint(ObjRs("qtd_ma"))

if quantidade_pedida > saldo_em_estoque then
 %>
  <body <%=colorbg1%>>
   <script language="javascript">
    alert("A QUANTIDADE PEDIDA E MAIOR DO QUE A QUANTIDADE EM ESTOQUE !");
    window.location = 'venda.asp'
   </script>
   <%
  Response.End
end if

estoque = saldo_em_estoque - qtd_ma

strSq2 = "Update t_uni Set qtd_ma='"&estoque&"' where cd_ma = "&cd_ma
Set ObjRs = objConn.Execute(strSq2)





strsql = "Insert into t_hist_uni (cd, cd_ma, nm_ma, qtd_ma, dt_ma, cd_func, nm_func2, loca, data) values ('"&cd&"', '"&cd_ma&"', '"&nm_ma&"', '"&qtd_ma&"', '"&dt_ma&"', '"&cd_func&"', '"&nm_func2&"', '"&loca	&"', '"&data&"')"
Set ObjRs = ObjConn.execute(strsql)

if error <> 0 then
   Response.Write "Ocorreu o seguinte erro "&err.description&"."
else%>

	<body <%=colorbg1%>>
<script language="javascript">
  if (confirm(' Gravado com sucesso [ <%=cdnf%> ]...\t\t\n\n» Deseja gerar o comprovante agora ?'))
   {
  	window.location = 'peruni.asp?cdfunc=<%=cd_func%>';
  	}else{
    window.location = 'venda.asp'
    }
   </script>
<%end if%>
[/ASP]

EU FIZ UM COD COM DUAS TABELAS COM OS MSMO VALORES COMO vocês FALARAM

MAS QUANDO

mas quando mando inserir os valores de um na outra se o cod da nota for igual a o sugerido

ai iserir os dados

na tabela 2

ai eu fiz um while mas ta dando pau

o q eu faço

valw galera...

Link para o comentário
Compartilhar em outros sites

  • 0

faca assim:

strSq2 = "Update t_uni Set qtd_ma='"&estoque&"' where cd_ma = "&cd_ma
objConn.Execute strSq2

strsql = "Insert into t_hist_uni (cd, cd_ma, nm_ma, qtd_ma, dt_ma, cd_func, nm_func2, loca, data) values ('"&cd&"', '"&cd_ma&"', '"&nm_ma&"', '"&qtd_ma&"', '"&dt_ma&"', '"&cd_func&"', '"&nm_func2&"', '"&loca &"', '"&data&"')"
ObjConn.execute strsql

q o seu while vai funcionar.

como você tava usando o objrs no execute, o recordset estava ficando zerado por isso o while não funcionava.

Link para o comentário
Compartilhar em outros sites

  • 0

ai cara fiz assim mas ta dando loop na maquina

de uma olhada ai



<!--#include file="conexao.asp"-->
<%
cdnf  = Request.QueryString("cdnf")

ObjConn.Open conex
strSq3 = "select * from t_venda where cd_nf = "&cdnf
Set ObjRs = objConn.Execute(strSq3)


cd_ma = ObjRs("cd_prod")
nm_ma = ObjRs("nm_prod")
qtd_ma = ObjRs("quant")


While NOT ObjRs.EOF


strSq0 = "select * from t_uni where cod = "&cd_ma
Set ObjRs = objConn.Execute(strSq0)




quantidade_pedida = qtd_ma
saldo_em_estoque = Cint(ObjRs("qtd_ma"))

if quantidade_pedida > saldo_em_estoque then
 %>
  <body <%=colorbg1%>>
   <script language="javascript">
    alert("A QUANTIDADE PEDIDA E MAIOR DO QUE A QUANTIDADE EM ESTOQUE !");
    window.location = 'venda.asp'
   </script>
   <%
  Response.End
end if

estoque = saldo_em_estoque - qtd_ma
strSq2 = "Update t_uni Set qtd_ma='"&estoque&"' where cd_ma = "&cd_ma
objConn.Execute strSq2
  
  
  objRS.MoveNext
  Wend

if error <> 0 then
   Response.Write "Ocorreu o seguinte erro "&err.description&"."
else%>

	<body>
<script language="javascript">
  if (confirm(' Gravado com sucesso [ <%=cdnf%> ]...\t\t\n\n» Deseja gerar o comprovante agora ?'))
   {
  	window.location = 'peruni.asp?cdfunc=<%=cd_func%>';
  	}else{
    window.location = 'venda.asp'
    }
   </script>
<%end if%>

valw

Link para o comentário
Compartilhar em outros sites

  • 0

cara entaum me fala como eu faço para q esse codigo aki da certo

<!--#include file="conexao.asp"-->
<%

ObjConn.Open conex


strSq3 = "select * from t_venda"
Set ObjRs = objConn.Execute(strSq3)
While NOT ObjRs.EOF

cd_ma = ObjRs("cd_prod")
nm_ma = ObjRs("nm_prod")
qtd_ma2 = ObjRs("quant")
nota = ObjRs("cd_nf")
cdnf  = Request.QueryString("cdnf")





If nota = cdnf then


strSq3 = "select * from t_uni where cod = "&cd_ma
Set ObjRs = objConn.Execute(strSq3)




quantidade_pedida = qtd_ma2
saldo_em_estoque = Cint(ObjRs("qtd_ma"))

if quantidade_pedida > saldo_em_estoque then
 %>
  <body <%=colorbg1%>>
   <script language="javascript">
    alert("A QUANTIDADE PEDIDA E MAIOR DO QUE A QUANTIDADE EM ESTOQUE !");
   javascript:history.back(-1)
   </script>
   <%
  Response.End
end if

estoque = saldo_em_estoque - quantidade_pedida

strSq2 = "Update t_uni Set qtd_ma='"&estoque&"' where cod = "&cd_ma
Set ObjRs = objConn.Execute(strSq2)






Else
End if


  objRS.MoveNext
  Wend







%>

falws

valw abraços

Link para o comentário
Compartilhar em outros sites

  • 0

tente assim:

ASP
<!--#include file="conexao.asp"-->

<%

Dim ObjRs2

Set ObjRs2 = Server.CreateObject ("ADODB.RecordSet")

ObjConn.Open conex

strSq3 = "select * from t_venda"

Set ObjRs = objConn.Execute(strSq3)

While NOT ObjRs.EOF

cd_ma = ObjRs("cd_prod")

nm_ma = ObjRs("nm_prod")

qtd_ma2 = ObjRs("quant")

nota = ObjRs("cd_nf")

cdnf = Request.QueryString("cdnf")

If nota = cdnf then

strSq3 = "select * from t_uni where cod = "&cd_ma

Set ObjRs2 = objConn.Execute(strSq3)

quantidade_pedida = qtd_ma2

saldo_em_estoque = Cint(ObjRs2("qtd_ma"))

if quantidade_pedida > saldo_em_estoque then

%>

<body <%=colorbg1%>>

<script language="javascript">

alert("A QUANTIDADE PEDIDA E MAIOR DO QUE A QUANTIDADE EM ESTOQUE !");

javascript:history.back(-1)

</script>

<%

Response.End

end if

estoque = saldo_em_estoque - quantidade_pedida

strSq2 = "Update t_uni Set qtd_ma='"&estoque&"' where cod = "&cd_ma

objConn.Execute strSq2

Else

End if

objRS.MoveNext

Wend

%>

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...