Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » SQL Server »

[SOLUCIONADO] pasar parametros a stored procedure mediante vba excel y recoger valor

Estas en el tema de pasar parametros a stored procedure mediante vba excel y recoger valor en el foro de SQL Server en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 29/09/2014, 09:14
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 11 años, 11 meses
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
  #2 (permalink)  
Antiguo 30/09/2014, 08:11
 
Fecha de Ingreso: abril-2012
Mensajes: 449
Antigüedad: 11 años, 11 meses
Puntos: 7
Respuesta: pasar parametros a stored procedure mediante vba excel y recoger valor

Cita:
Iniciado por maialenlopez Ver Mensaje
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!!!
YA lo he solucionado haciendo lo siguiente:
Código vba:
Ver original
  1. Set cmd = New ADODB.Command
  2. cmd.CommandText = "F_TARE_horprogRem"
  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(0).Value = idTare
  9. Set prmOut = cmd.CreateParameter("@CANTIDAD", adSmallInt, adParamOutput)
  10. cmd.Parameters.Append prmOut
  11.  
  12.  
  13. 'Execute the Stored Procedure
  14. Set adores = cmd.Execute
  15. 'Dim numero_columnas As Integer
  16. 'numero_columnas = adores.Fields.Count
  17.  
  18. Dim valor As Integer
  19. valor = cmd.Parameters("@CANTIDAD").Value

__________________
Gracias por todo;

Un saludo

Etiquetas: excel, mediante, parametros, procedure, recoger, select, stored, valor, vba
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 00:34.