Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/09/2014, 09:14
maialenlopez
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 12 años, 1 mes
Puntos: 7
pasar parametros a stored procedure mediante vba excel y recoger valor

Hola,

Le estoy dando mil vueltas a esto y no consigo pasarle parámetros a un stored procedure que tengo en base de datos y tampoco consigo recoger el valor que me devuelve.

este es el stored:
Código sql:
Ver original
  1. ALTER PROCEDURE [dbo].[HORAS_PROGRAMACION]
  2.     @IDTARE AS INTEGER
  3. AS
  4. SELECT 'Hrs' = SUM(HOR_PACT) FROM FSGA_PACT WITH(NOLOCK)
  5.        INNER JOIN ( SELECT
  6.        FSGA_TRUS.ID_EMPR , FSGA_TRUS.ID_CLNT, FSGA_TRUS.ID_PROY, FSGA_TRUS.ID_TARE, FSGA_TRUS.ID_USUA
  7.        FROM FSGA_TRUS WITH(NOLOCK)
  8.        INNER JOIN FSGA_CATU WITH(NOLOCK)
  9.            ON FSGA_TRUS.ID_EMPR = FSGA_CATU.ID_EMPR
  10.            AND FSGA_TRUS.ID_AREA = FSGA_CATU.ID_AREA
  11.            AND FSGA_TRUS.ID_CATU = FSGA_CATU.ID_CATU
  12.        WHERE COD_CATU IN ('TCINS','TCINJ','TCBIS','TCBIJ','PSDES','PJDES')
  13. ) P
  14. ON FSGA_PACT.ID_EMPR = P.ID_EMPR AND FSGA_PACT.ID_CLNT = P.ID_CLNT AND FSGA_PACT.ID_PROY = P.ID_PROY
  15. AND FSGA_PACT.ID_TARE = P.ID_TARE WHERE  ID_AREA IN (2,5,6,7,8,9,102)
  16. AND ( FSGA_PACT.ID_USUA NOT IN ( SELECT ID_USUA
  17.         FROM FSGA_USCT WITH(NOLOCK) INNER JOIN FSGA_CATU WITH(NOLOCK) ON FSGA_USCT.ID_EMPR = FSGA_CATU.ID_EMPR
  18.         AND FSGA_USCT.ID_AREA = FSGA_CATU.ID_AREA AND FSGA_USCT.ID_CATU = FSGA_CATU.ID_CATU
  19.         WHERE COD_CATU IN ('GEDES','RSBIS','RSPRD','SUINT','GEDES','RSBIS','GEDES','SUPRG')
  20.         AND FFIN_USCT IS NULL)
  21.         OR  FSGA_PACT.ID_USUA =  P.ID_USUA
  22.         )
  23. AND NOT (fsga_pact.id_tptr = 17 AND fsga_pact.id_area = 2)
  24. AND NOT (fsga_pact.id_tptr = 16 AND fsga_pact.id_area = 5)
  25. AND NOT (fsga_pact.id_tptr = 8 AND fsga_pact.id_area = 102)
  26. AND NOT (fsga_pact.id_tptr = 1 AND fsga_pact.id_area = 107)
  27. AND FSGA_PACT.ID_TARE = @IDTARE

Y esto es lo que hago desde una macro de excel pero no consigo paserle ni el parámetro ni recoger el valor:
Código vba:
Ver original
  1. Set cmd = New ADODB.Command
  2. cmd.CommandText = "HORAS_PROGRAMACION"
  3. cmd.CommandType = adCmdStoredProc
  4. cmd.ActiveConnection = adoconn
  5.  
  6. Set prm = cmd.CreateParameter("@IDTARE", adInteger, adParamInput)
  7. cmd.Parameters.Append prm
  8. cmd.Parameters(1).Value = idTare
  9.  
  10. 'Execute the Stored Procedure
  11. Set Rst = cmd.Execute
  12.  
  13.  
  14. If Not Rst.EOF Then
  15.     ' Update Real Hours
  16.     sheetx.Range("V" & ActiveCell.Row).Value = Rst
  17.     txtProg.Value = Rst
  18.     'MsgBox "Horas imputadas a la tarea: " & adores(0).Value, vbInformation
  19. Else
  20.     sheetx.Range("V" & ActiveCell.Row).Value = 0
  21.     txtProg.Value = 0
  22.     MsgBox "¡No existen horas imputadas a la tarea!", vbExclamation
  23. End If

alguien puede ayudarme? me estoy volviendo loca!!!
__________________
Gracias por todo;

Un saludo