Foros del Web » Programando para Internet » ASP Clásico »

como ejecutar 2 consultas en una sola conexion y q objeto manejar

Estas en el tema de como ejecutar 2 consultas en una sola conexion y q objeto manejar en el foro de ASP Clásico en Foros del Web. Hola,tengo un problema, quiero eejecutar 2 consultas en una misma conexion ya que hago un insert a una tabla temporal la cual se destruye una ...
  #1 (permalink)  
Antiguo 22/06/2010, 10:09
 
Fecha de Ingreso: noviembre-2007
Mensajes: 504
Antigüedad: 16 años, 5 meses
Puntos: 2
como ejecutar 2 consultas en una sola conexion y q objeto manejar

Hola,tengo un problema, quiero eejecutar 2 consultas en una misma conexion ya que hago un insert a una tabla temporal la cual se destruye una ves cerrada la xonexion a la db, el problema es que no se que objeto user ya que una consulta es de seleccion e insercion y la otra solo de seleccion es decir, las 2 consultas son las siguientes:
Código SQL:
Ver original
  1. SELECT h.hora AS hora1,h.marca,h.codoptima AS codoptimaT,h.target,P.CODOPTIMA,O.CODIGO,
  2. p.hora,p.peso,p.vaso,p.fecha,o.linea,o.tubo
  3. INTO #checho
  4. FROM pesos AS p, optimas AS o,htargets AS h
  5. WHERE o.codigo = p.codOptima AND o.linea = 'L01S'
  6. AND o.tubo LIKE '%' AND p.fecha BETWEEN '2010-06-21 08:00' AND '2010-06-21 08:30'
  7. AND p.hora='8:00 - 8:30' AND h.codoptima = o.codigo AND h.hora='8:00 - 8:30'
  8.     SELECT *,(SELECT COUNT(1)total FROM #checho) AS totality FROM #checho
como se ve una selecciona e inserta y la otra solo selecciona lo insertado:
Código ASP:
Ver original
  1. <%
  2.  
  3. dim conexion,calendar1,calendar2,registros,linea,hora,test
  4. calendar1=request.form("calendar1")
  5. calendar2=request.form("calendar2")
  6. linea=request.form("linea")
  7. Tubo=request.form("tubo")
  8. hora=request.form("hora")
  9. test=("SELECT h.hora,h.marca,h.codoptima,h.target,P.CODOPTIMA,O.CODIGO,p.hora,p.peso,p.vaso,p.fecha, o.linea,o.tubo FROM pesos as p, optimas as o,htargets as h where o.codigo = p.codOptima and o.linea = '"&linea&"' and o.tubo LIKE '"&tubo&"'  AND p.fecha Between '"&calendar1&"' AND '"&calendar2&"' AND p.hora='"&hora&"'and h.codoptima = o.codigo and h.hora='"&hora&"'")
  10.         SET conexion=Server.CreateObject("ADODB.Connection")
  11.         conexion.Open "PROVIDER=SQLOLEDB; DATA SOURCE=VALP-MESSRV02;UID=sa;PWD=messrv;DATABASE=wasp "
  12.         SET registros=Server.CreateObject("ADODB.RecordSet")
  13.         'registros.open"SELECT peso,tubo from pesos where fecha  between '"&calendar1&"' AND '"&calendar2&"'",conexion
  14.  
  15.         'registros.open"SELECT h.hora AS hora1,h.marca,h.codoptima AS codoptimaT,h.target,P.CODOPTIMA,O.CODIGO,p.hora,p.peso,p.vaso,p.fecha,o.linea,o.tubo INTO #c FROM pesos AS p, optimas AS o,htargets AS h WHERE o.codigo = p.codOptima AND o.linea = '"&linea&"' AND o.tubo ='"&tubo&"' AND p.fecha BETWEEN '"&calendar1&"' AND '"&calendar2&"' AND p.hora='"&hora&"' AND h.codoptima = o.codigo AND h.hora='"&hora&"'",conexion
  16.  
  17.  
  18.  
  19.  
  20.     registros.open"SELECT h.hora,h.marca,h.codoptima,h.target,P.CODOPTIMA,O.CODIGO,p.hora,p.peso,p.vaso,p.fecha, o.linea,o.tubo FROM pesos as p, optimas as o,htargets as h where o.codigo = p.codOptima and o.linea = '"&linea&"' and o.tubo ='"&tubo&"'  AND h.fecha Between '"&calendar1&"' AND '"&calendar2&"'  AND p.fecha Between '"&calendar1&"' AND '"&calendar2&"' AND p.hora='"&hora&"'and h.codoptima = o.codigo and h.hora='"&hora&"'" ,conexion
  21.     'registros.open"SELECT p.hora,p.peso,p.vaso,p.fecha, o.linea,o.tubo FROM pesos as p, optimas as o where o.codigo = p.codOptima and o.linea = 'L15N' and o.tubo LIKE '%'  AND p.fecha Between '2010-06-14 09:00:00.000' AND '2010-06-14 09:30:00.000' AND p.hora='9:00 - 9:30'" ,conexion    
  22.     'SELECT h.codoptima,h.target,P.CODOPTIMA,O.CODIGO,p.hora,p.peso,p.vaso,p.fecha, o.linea,o.tubo,o.codigo FROM pesos as p, optimas as o,htargets as h where o.codigo = p.codOptima and o.linea = 'L07N' and o.tubo LIKE '%' AND p.fecha Between '2010-06-14 09:30' AND '2010-06-14 10:00' AND p.hora='9:30 - 10:00' and h.codoptima = o.codigo
  23.  
  24.     dim a
  25.     do while not registros.eof
  26. a=cint(registros.fields("target"))
  27.  
  28.         response.write("<tr>")
  29.         response.write("<td>"&registros.fields("linea")&"</td>")
  30.         response.write("<td>"&registros.fields("peso")&"</td>")
  31.         response.write("<td>"&registros.fields("target")&"</td>")
  32.         'response.write("<td>"&a&"</td>")
  33.         response.write("<td>"&registros.fields("marca")&"</td>")
  34.         response.write("<td>"&registros.fields("vaso")&"</td>")
  35.         response.write("<td>"&registros.fields("tubo")&"</td>")
  36.         response.write("<td>"&registros.fields("fecha")&"</td>")
  37.         registros.movenext
  38.  
  39.  
  40. loop
  41.  
  42. conexion.close
  43. response.write(test) '<--Test Debug
  44. 'RESPONSE.WRITE("<br>")
  45.     dim codoptima
  46.  
  47. if  linea="L01N" AND tubo="A" then
  48.             codoptima=30
  49. elseif _
  50.     linea="L01N" AND tubo="B" then
  51.             codoptima=31
  52. elseif  linea="L01N" AND tubo="C" then
  53.             codoptima=32
  54. elseif  linea="L01S" AND tubo="D" then
  55.             codoptima=33
  56. elseif  linea="L01S" AND tubo="E" then
  57.             codoptima=34
  58. elseif  linea="L01S" AND tubo="F" then
  59.             codoptima=35
  60.            
  61. elseif  linea="L02N" AND tubo="A"   then
  62.             codoptima=54
  63. elseif  linea="L02N" AND tubo="B" then
  64.             codoptima=55
  65. elseif  linea="L02N" AND tubo="C" then
  66.             codoptima=56
  67.                        
  68. elseif  linea="L02N" AND tubo="D" then
  69.             codoptima=57
  70. elseif  linea="L02N" AND tubo="E" then
  71.             codoptima=58
  72. elseif  linea="L02N" AND tubo="F" then
  73.             codoptima=59
  74.    
  75. elseif  linea="L03N" AND tubo="A"   then
  76.             codoptima=60
  77. elseif  linea="L03N" AND tubo="B"   then
  78.             codoptima=61
  79. elseif  linea="L03N" AND tubo="C"   then
  80.             codoptima=62       
  81.            
  82. elseif  linea="L03S" AND tubo="D"   then
  83.             codoptima=63
  84. elseif  linea="L03S" AND tubo="E"   then
  85.             codoptima=64
  86. elseif  linea="L03S" AND tubo="F"    then
  87.             codoptima=65
  88.            
  89. elseif  linea="L06N" AND tubo="A"   then
  90.             codoptima=36
  91. elseif  linea="L06N" AND tubo="B"       then
  92.             codoptima=37
  93. elseif  linea="L06N" AND tubo="C"       then
  94.             codoptima=38
  95.            
  96. elseif  linea="L06S" AND tubo="D"       then
  97.             codoptima=39
  98. elseif  linea="L06S" AND tubo="E"       then
  99.             codoptima=40
  100. elseif  linea="L06S" AND tubo="F"       then
  101.             codoptima=41           
  102.        
  103. elseif  linea="L07N" AND tubo="A"       then
  104.             codoptima=42
  105. elseif  linea="L07N" AND tubo="B"       then
  106.             codoptima=43
  107. elseif  linea="L07N" AND tubo="C"       then
  108.             codoptima=44
  109. elseif  linea="L07S" AND tubo="D"       then
  110.             codoptima=45
  111. elseif  linea="L07S" AND tubo="E"       then
  112.             codoptima=46
  113. elseif  linea="L07S" AND tubo="F"       then
  114.             codoptima=47                   
  115. elseif  linea="L09N" AND tubo="A"       then
  116.             codoptima=48
  117. elseif  linea="L09N" AND tubo="B"       then
  118.             codoptima=49
  119. elseif  linea="L09N" AND tubo="C"       then
  120.             codoptima=50   
  121. elseif  linea="L09S" AND tubo="D"       then
  122.             codoptima=51
  123. elseif  linea="L09S" AND tubo="E"       then
  124.             codoptima=52
  125. elseif  linea="L09S" AND tubo="F"       then
  126.             codoptima=53       
  127. elseif  linea="L14N" AND tubo="A"       then
  128.             codoptima=76
  129. elseif  linea="L15N" AND tubo="A"       then
  130.             codoptima=82
  131. elseif  linea="L15N" AND tubo="B"       then
  132.             codoptima=83
  133. elseif  linea="L15N" AND tubo="C"       then
  134.             codoptima=84
  135. elseif  linea="L15S" AND tubo="D"       then
  136.             codoptima=85
  137. elseif  linea="L15S" AND tubo="E"       then
  138.             codoptima=86
  139. elseif  linea="L15S" AND tubo="F"       then
  140.             codoptima=87
  141. elseif      linea="L16N" AND tubo="A"   then
  142.             codoptima=88
  143. elseif  linea="L16N" AND tubo="B"       then
  144.             codoptima=89
  145. elseif  linea="L16N" AND tubo="C"       then
  146.             codoptima=90
  147. elseif  linea="L16S" AND tubo="D"       then
  148.             codoptima=91
  149. elseif  linea="L16S" AND tubo="E"       then
  150.             codoptima=92
  151. elseif  linea="L16S" AND tubo="F"       then
  152.             codoptima=93           
  153. elseif  linea="L17N" AND tubo="A"       then
  154.             codoptima=94
  155. elseif  linea="L17N" AND tubo="B"       then
  156.             codoptima=95
  157. elseif  linea="L17N" AND tubo="C"       then
  158.             codoptima=96
  159. elseif  linea="L17S" AND tubo="D"       then
  160.             codoptima=97
  161. elseif  linea="L17S" AND tubo="E"       then
  162.             codoptima=98
  163. elseif  linea="L17S" AND tubo="F"       then
  164.             codoptima=99
  165. elseif  linea="L19N" AND tubo="A"       then
  166.             codoptima=104
  167. elseif  linea="L19N" AND tubo="B"       then
  168.             codoptima=102
  169. elseif  linea="L19N" AND tubo="C"       then
  170.             codoptima=103          
  171.        
  172.     end if     
  173.  
  174.  
  175.             'SELECT p.peso,p.tubo,p.fecha, o.linea FROM pesos as p, optimas as o where o.codigo = p.codOptima and o.linea = 'L02N'  AND p.fecha Between '2010-05-11 09:42:34.000' AND '2010-05-11 09:42:39.000'
  176.             SET conexion2=Server.CreateObject("ADODB.Connection")
  177.             conexion2.Open "PROVIDER=SQLOLEDB; DATA SOURCE=VALP-MESSRV02;UID=sa;PWD=messrv;DATABASE=wasp "
  178.             SET registros2=Server.CreateObject("ADODB.RecordSet")
  179.        
  180.         registros2.open"SELECT AVG(PESO)as peso from pesos where fecha Between '"&calendar1&"' AND '"&calendar2&"'AND hora='"&hora&"' AND codoptima='"&codoptima&"'",conexion2
  181.         'RESPONSE.WRITE("SELECT AVG(PESO)as peso from pesos where fecha Between '"&calendar1&"' AND '"&calendar2&"'AND hora='"&hora&"' AND codoptima='"&codoptima&"'")
  182.         do while not registros2.eof
  183.         c=cint(registros2.fields("peso"))
  184.         b=(a-c)/a
  185.         response.write("Promedio: "&registros2.fields("peso")&"")
  186.     '############## Aritmetica ####################
  187.     ' C = Promedio  WHERE B=(a-c)/a
  188.     ' A = Target
  189.         response.write("<br> Op: "&b&"<br>")
  190.            
  191.         saving=(c-a)
  192.        
  193.         registros2.movenext
  194.     loop
  195.        
  196.         conexion2.close
  197.        
  198. %>
  #2 (permalink)  
Antiguo 22/06/2010, 10:20
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 3 meses
Puntos: 146
Respuesta: como ejecutar 2 consultas en una sola conexion y q objeto manejar

Yo no entendí, y tampoco entiendo cuál es la diferencia con respecto al tema que abriste donde ya mencionabas esto mismo

Tiene muchos mensajes abiertos donde tocas temas del mismo problema, y esto esta ya siendo confuso
  #3 (permalink)  
Antiguo 22/06/2010, 10:45
 
Fecha de Ingreso: noviembre-2007
Mensajes: 504
Antigüedad: 16 años, 5 meses
Puntos: 2
Respuesta: como ejecutar 2 consultas en una sola conexion y q objeto manejar

Hola, la como se ve e la consulta SQL hago consultas la primera crea una tabla temporal donde primero obtiene los datos con un select y posteriormente los inserta en la tabla temporal, misma que sera eliminada automaticamente al cerrar la sesion en la base de datos.
La segunda parte:
SELECT *,(SELECT count(1)total FROM #checho) as totality from #checho
Me selecciona todos los datos de esa tabla temporal. Entonces lo que quiero hacer con ASP es que en una sola conexion haga estas dos consultas por que si primero hago la primera que es crear la tabla temporal e insertar los datos obtenidos en el select y cierro conexion para despeus abrir otra y hacer el select que moestre anteriormente no me mostrara nada ya que al cerrar la conexion esa tabla temporal se elimina automaticamente.
Perdon por el tema anterior es distinto, en ese tuve que crear 2 conexiones una para el select y otro para el promedio.
Saludos
  #4 (permalink)  
Antiguo 22/06/2010, 10:54
Avatar de u_goldman
Moderador
 
Fecha de Ingreso: enero-2002
Mensajes: 8.031
Antigüedad: 22 años, 4 meses
Puntos: 98
Respuesta: como ejecutar 2 consultas en una sola conexion y q objeto manejar

Haz un stored procedure donde tengas la creacion de la tabla temporal y la consulta, llamalo desde tu codigo ASP.

Saludos
__________________
"El hombre que ha empezado a vivir seriamente por dentro, empieza a vivir más sencillamente por fuera."
-- Ernest Hemingway
  #5 (permalink)  
Antiguo 22/06/2010, 12:02
 
Fecha de Ingreso: noviembre-2007
Mensajes: 504
Antigüedad: 16 años, 5 meses
Puntos: 2
Respuesta: como ejecutar 2 consultas en una sola conexion y q objeto manejar

Hola, ya hice el procedure pero me da error en la linea donde lo ejecuto:
Microsoft OLE DB Provider for SQL Server error '80040e14'

Line 1: Incorrect syntax near '2010'.

/Mes/Asp/was2/more2.asp, line 93
La cual aqui es la linea 19
Código ASP:
Ver original
  1. <&#37;
  2.  
  3. dim conexion,calendar1,calendar2,registros,linea,hora,test
  4. calendar1=request.form("calendar1")
  5. calendar2=request.form("calendar2")
  6. linea=request.form("linea")
  7. Tubo=request.form("tubo")
  8. hora=request.form("hora")
  9. test=("SELECT h.hora,h.marca,h.codoptima,h.target,P.CODOPTIMA,O.CODIGO,p.hora,p.peso,p.vaso,p.fecha, o.linea,o.tubo FROM pesos as p, optimas as o,htargets as h where o.codigo = p.codOptima and o.linea = '"&linea&"' and o.tubo LIKE '"&tubo&"'  AND p.fecha Between '"&calendar1&"' AND '"&calendar2&"' AND p.hora='"&hora&"'and h.codoptima = o.codigo and h.hora='"&hora&"'")
  10.         SET conexion=Server.CreateObject("ADODB.Connection")
  11.         conexion.Open "PROVIDER=SQLOLEDB; DATA SOURCE=VALP-MESSRV02;UID=sa;PWD=messrv;DATABASE=wasp "
  12.         SET registros=Server.CreateObject("ADODB.RecordSet")
  13.         'registros.open"SELECT peso,tubo from pesos where fecha  between '"&calendar1&"' AND '"&calendar2&"'",conexion
  14.  
  15.         'registros.open"SELECT h.hora AS hora1,h.marca,h.codoptima AS codoptimaT,h.target,P.CODOPTIMA,O.CODIGO,p.hora,p.peso,p.vaso,p.fecha,o.linea,o.tubo INTO #c FROM pesos AS p, optimas AS o,htargets AS h WHERE o.codigo = p.codOptima AND o.linea = '"&linea&"' AND o.tubo ='"&tubo&"' AND p.fecha BETWEEN '"&calendar1&"' AND '"&calendar2&"' AND p.hora='"&hora&"' AND h.codoptima = o.codigo AND h.hora='"&hora&"'",conexion
  16.  
  17.  
  18.  
  19.         registros.open"EXEC cuenta '"&calendar1&",'"&calendar2&"','"&linea&"','"&tubo&"','"&hora&"'",conexion
  20.     'USED'registros.open"SELECT h.hora,h.marca,h.codoptima,h.target,P.CODOPTIMA,O.CODIGO,p.hora,p.peso,p.vaso,p.fecha, o.linea,o.tubo FROM pesos as p, optimas as o,htargets as h where o.codigo = p.codOptima and o.linea = '"&linea&"' and o.tubo ='"&tubo&"'  AND h.fecha Between '"&calendar1&"' AND '"&calendar2&"'  AND p.fecha Between '"&calendar1&"' AND '"&calendar2&"' AND p.hora='"&hora&"'and h.codoptima = o.codigo and h.hora='"&hora&"'" ,conexion
  21.     'registros.open"SELECT p.hora,p.peso,p.vaso,p.fecha, o.linea,o.tubo FROM pesos as p, optimas as o where o.codigo = p.codOptima and o.linea = 'L15N' and o.tubo LIKE '%'  AND p.fecha Between '2010-06-14 09:00:00.000' AND '2010-06-14 09:30:00.000' AND p.hora='9:00 - 9:30'" ,conexion    
  22.     'SELECT h.codoptima,h.target,P.CODOPTIMA,O.CODIGO,p.hora,p.peso,p.vaso,p.fecha, o.linea,o.tubo,o.codigo FROM pesos as p, optimas as o,htargets as h where o.codigo = p.codOptima and o.linea = 'L07N' and o.tubo LIKE '%' AND p.fecha Between '2010-06-14 09:30' AND '2010-06-14 10:00' AND p.hora='9:30 - 10:00' and h.codoptima = o.codigo
  23.  
  24.     dim a
  25.     do while not registros.eof
  26. a=cint(registros.fields("target"))
  27.  
  28.         response.write("<tr>")
  29.         response.write("<td>"&registros.fields("linea")&"</td>")
  30.         response.write("<td>"&registros.fields("peso")&"</td>")
  31.         response.write("<td>"&registros.fields("target")&"</td>")
  32.         'response.write("<td>"&a&"</td>")
  33.         response.write("<td>"&registros.fields("marca")&"</td>")
  34.         response.write("<td>"&registros.fields("vaso")&"</td>")
  35.         response.write("<td>"&registros.fields("tubo")&"</td>")
  36.         response.write("<td>"&registros.fields("fecha")&"</td>")
  37.         registros.movenext
  38.  
  39.  
  40. loop
  41.  
  42. conexion.close
  43. response.write(test) '<--Test Debug
  44. 'RESPONSE.WRITE("<br>")
  45.     dim codoptima
  46.  
  47. if  linea="L01N" AND tubo="A" then
  48.             codoptima=30
  49. elseif _
  50.     linea="L01N" AND tubo="B" then
  51.             codoptima=31
  52. elseif  linea="L01N" AND tubo="C" then
  53.             codoptima=32
  54. elseif  linea="L01S" AND tubo="D" then
  55.             codoptima=33
  56. elseif  linea="L01S" AND tubo="E" then
  57.             codoptima=34
  58. elseif  linea="L01S" AND tubo="F" then
  59.             codoptima=35
  60.            
  61. elseif  linea="L02N" AND tubo="A"   then
  62.             codoptima=54
  63. elseif  linea="L02N" AND tubo="B" then
  64.             codoptima=55
  65. elseif  linea="L02N" AND tubo="C" then
  66.             codoptima=56
  67.                        
  68. elseif  linea="L02N" AND tubo="D" then
  69.             codoptima=57
  70. elseif  linea="L02N" AND tubo="E" then
  71.             codoptima=58
  72. elseif  linea="L02N" AND tubo="F" then
  73.             codoptima=59
  74.    
  75. elseif  linea="L03N" AND tubo="A"   then
  76.             codoptima=60
  77. elseif  linea="L03N" AND tubo="B"   then
  78.             codoptima=61
  79. elseif  linea="L03N" AND tubo="C"   then
  80.             codoptima=62       
  81.            
  82. elseif  linea="L03S" AND tubo="D"   then
  83.             codoptima=63
  84. elseif  linea="L03S" AND tubo="E"   then
  85.             codoptima=64
  86. elseif  linea="L03S" AND tubo="F"    then
  87.             codoptima=65
  88.            
  89. elseif  linea="L06N" AND tubo="A"   then
  90.             codoptima=36
  91. elseif  linea="L06N" AND tubo="B"       then
  92.             codoptima=37
  93. elseif  linea="L06N" AND tubo="C"       then
  94.             codoptima=38
  95.            
  96. elseif  linea="L06S" AND tubo="D"       then
  97.             codoptima=39
  98. elseif  linea="L06S" AND tubo="E"       then
  99.             codoptima=40
  100. elseif  linea="L06S" AND tubo="F"       then
  101.             codoptima=41           
  102.        
  103. elseif  linea="L07N" AND tubo="A"       then
  104.             codoptima=42
  105. elseif  linea="L07N" AND tubo="B"       then
  106.             codoptima=43
  107. elseif  linea="L07N" AND tubo="C"       then
  108.             codoptima=44
  109. elseif  linea="L07S" AND tubo="D"       then
  110.             codoptima=45
  111. elseif  linea="L07S" AND tubo="E"       then
  112.             codoptima=46
  113. elseif  linea="L07S" AND tubo="F"       then
  114.             codoptima=47                   
  115. elseif  linea="L09N" AND tubo="A"       then
  116.             codoptima=48
  117. elseif  linea="L09N" AND tubo="B"       then
  118.             codoptima=49
  119. elseif  linea="L09N" AND tubo="C"       then
  120.             codoptima=50   
  121. elseif  linea="L09S" AND tubo="D"       then
  122.             codoptima=51
  123. elseif  linea="L09S" AND tubo="E"       then
  124.             codoptima=52
  125. elseif  linea="L09S" AND tubo="F"       then
  126.             codoptima=53       
  127. elseif  linea="L14N" AND tubo="A"       then
  128.             codoptima=76
  129. elseif  linea="L15N" AND tubo="A"       then
  130.             codoptima=82
  131. elseif  linea="L15N" AND tubo="B"       then
  132.             codoptima=83
  133. elseif  linea="L15N" AND tubo="C"       then
  134.             codoptima=84
  135. elseif  linea="L15S" AND tubo="D"       then
  136.             codoptima=85
  137. elseif  linea="L15S" AND tubo="E"       then
  138.             codoptima=86
  139. elseif  linea="L15S" AND tubo="F"       then
  140.             codoptima=87
  141. elseif      linea="L16N" AND tubo="A"   then
  142.             codoptima=88
  143. elseif  linea="L16N" AND tubo="B"       then
  144.             codoptima=89
  145. elseif  linea="L16N" AND tubo="C"       then
  146.             codoptima=90
  147. elseif  linea="L16S" AND tubo="D"       then
  148.             codoptima=91
  149. elseif  linea="L16S" AND tubo="E"       then
  150.             codoptima=92
  151. elseif  linea="L16S" AND tubo="F"       then
  152.             codoptima=93           
  153. elseif  linea="L17N" AND tubo="A"       then
  154.             codoptima=94
  155. elseif  linea="L17N" AND tubo="B"       then
  156.             codoptima=95
  157. elseif  linea="L17N" AND tubo="C"       then
  158.             codoptima=96
  159. elseif  linea="L17S" AND tubo="D"       then
  160.             codoptima=97
  161. elseif  linea="L17S" AND tubo="E"       then
  162.             codoptima=98
  163. elseif  linea="L17S" AND tubo="F"       then
  164.             codoptima=99
  165. elseif  linea="L19N" AND tubo="A"       then
  166.             codoptima=104
  167. elseif  linea="L19N" AND tubo="B"       then
  168.             codoptima=102
  169. elseif  linea="L19N" AND tubo="C"       then
  170.             codoptima=103          
  171.        
  172.     end if     
  173.  
  174.  
  175.             'SELECT p.peso,p.tubo,p.fecha, o.linea FROM pesos as p, optimas as o where o.codigo = p.codOptima and o.linea = 'L02N'  AND p.fecha Between '2010-05-11 09:42:34.000' AND '2010-05-11 09:42:39.000'
  176.             SET conexion2=Server.CreateObject("ADODB.Connection")
  177.             conexion2.Open "PROVIDER=SQLOLEDB; DATA SOURCE=VALP-MESSRV02;UID=sa;PWD=messrv;DATABASE=wasp "
  178.             SET registros2=Server.CreateObject("ADODB.RecordSet")
  179.        
  180.         registros2.open"SELECT AVG(PESO)as peso from pesos where fecha Between '"&calendar1&"' AND '"&calendar2&"'AND hora='"&hora&"' AND codoptima='"&codoptima&"'",conexion2
  181.         'RESPONSE.WRITE("SELECT AVG(PESO)as peso from pesos where fecha Between '"&calendar1&"' AND '"&calendar2&"'AND hora='"&hora&"' AND codoptima='"&codoptima&"'")
  182.         do while not registros2.eof
  183.         c=cint(registros2.fields("peso"))
  184.         b=(a-c)/a
  185.         response.write("Promedio: "&registros2.fields("peso")&"")
  186.     '############## Aritmetica ####################
  187.     ' C = Promedio  WHERE B=(a-c)/a
  188.     ' A = Target
  189.         response.write("<br> Op: "&b&"<br>")
  190.            
  191.         saving=(c-a)
  192.        
  193.         registros2.movenext
  194.     loop
  195.        
  196.         conexion2.close
  197.        
  198. %>
  #6 (permalink)  
Antiguo 22/06/2010, 12:15
Avatar de u_goldman
Moderador
 
Fecha de Ingreso: enero-2002
Mensajes: 8.031
Antigüedad: 22 años, 4 meses
Puntos: 98
Respuesta: como ejecutar 2 consultas en una sola conexion y q objeto manejar

Tienes que ver que tus variables tengan valores correctos y que aquellas variables de texto esten correctamente formadas, por ejemplo a golpe de vista, encuentro que la siguiente variable no esta correctamente formada:

'"&calendar1&", <-- Le falta un apóstrofe.

Imprime tus valores uno por uno...depura

Saludos
__________________
"El hombre que ha empezado a vivir seriamente por dentro, empieza a vivir más sencillamente por fuera."
-- Ernest Hemingway
  #7 (permalink)  
Antiguo 22/06/2010, 21:32
 
Fecha de Ingreso: noviembre-2007
Mensajes: 504
Antigüedad: 16 años, 5 meses
Puntos: 2
Respuesta: como ejecutar 2 consultas en una sola conexion y q objeto manejar

Holaaa ya quedoo muchas gracias
  #8 (permalink)  
Antiguo 23/06/2010, 10:45
Avatar de u_goldman
Moderador
 
Fecha de Ingreso: enero-2002
Mensajes: 8.031
Antigüedad: 22 años, 4 meses
Puntos: 98
Respuesta: como ejecutar 2 consultas en una sola conexion y q objeto manejar

Por nadas
__________________
"El hombre que ha empezado a vivir seriamente por dentro, empieza a vivir más sencillamente por fuera."
-- Ernest Hemingway

Etiquetas: conexion, ejecutar, manejar, objeto
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:00.