Solved

use stored procedure from inside program

Posted on 2007-03-20
5
201 Views
Last Modified: 2010-04-30
I have a very long sql query that i made into a stored procedure.
ii don't know how to call the stored procedure. i need to pass 3 parameters to it.

this is how the query was run from the program:

        strSql = ""
        strSql = strSql & " " & _
                 "   SELECT    1 level , " & _
                 "             ord.order_id , " & _
                 "             ord.client , " & _
                 "             ord.line_no , " & _
                 "             ' ' dispatch_date , " & _
                 "             -1 item_owner , " & _
                 "             ' ' stock_location , " & _
                 "             ' ' return_action , " & _
                 "             ' ' item_class " & _
                 "     FROM    asodetail ord " & _
                 "    WHERE    ord.order_id = '" & m_strOrderNumber & "' " & _
                 "      AND    ord.client = '" & m_strClient & "' " & _
                 "      AND    ord.order_id NOT IN ( SELECT order_id FROM bretheader WHERE client = '" & m_strClient & "' ) "
        strSql = strSql & " UNION ALL " & _
                 "   SELECT    2 level , " & _
                 "             ord.order_id , " & _
                 "             ord.client , " & _
                 "             ord.line_no , " & _
             
                 "             ' ' return_action , " & _
                 "             ' ' item_class " & _
                 "     FROM    asodetail ord LEFT JOIN algrelvalue fly ON ( ord.article_id = fly.article_id " & _
                 "                                                      AND ord.client = fly.client " & _
                 "                                                      AND fly.rel_attr_id = 'V7' ) " & _
                 "                           LEFT JOIN bhjpackageviewhighjump hj ON ( ord.order_id = hj.order_id " & _
                 "                                                             AND ord.client = hj.client " & _
                 "                                                             AND hj.job_id = " & m_lngHighJumpToAgressoJobId & ") "
        strSql = strSql & " " & _
                 "                           LEFT JOIN algudispatch dis ON ( ord.order_id = dis.order_id " & _
                 "                                                       AND ord.article_id = dis.article_id " & _
                 "                                                       AND dis.status = 4 ) " & _
                 "    WHERE    (    (     COALESCE ( CASE WHEN fly.rel_value = ' ' THEN 'NA' ELSE fly.rel_value END , 'NA' ) = 'NA' " & _
                 "                    AND ord.kit_type = '2' ) " & _
                 "               OR ( ord.kit_type = '0' ) ) " & _
                 "      AND    ord.order_id = '" & m_strOrderNumber & "' " & _
                 "      AND    ord.client = '" & m_strClient & "' "
             
   
     Set rstSelect = m_cnnAgresso.Execute(strSql)



the name of the procedure and its parameters is:

proc_get_order_details ( @order_id int, @client char(2),  @job_id int)

0
Comment
Question by:itortu
  • 2
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
nike_golf earned 180 total points
ID: 18759797
I'm currently using the following to run a stored procedure on Mysql:

'Execute stored procedures on MYSQL DB to populate smaller table sizes for faster loading
 sql = "Call cardnos('" & Format(Date - 14, "yyyy-mm-dd") & "')"

in your case I'm guessing it might look like the following:

...
sql = "Call proc_get_order_details ('" & order_id & "','" &  client & "','" & job_id & "')"
conn.Execute sql, , adCmdText
...

NG,
0
 

Author Comment

by:itortu
ID: 18764035
i am doing it this way


strSql = ""
strSql = "Call proc_get_order_details ('" & m_strOrderNumber & "','" & m_strClient & "','" & m_lngHighJumpToAgressoJobId & "')"
Set rstSelect = m_cnnAgresso.Execute(strSql)

does it look correct to you?


                         
0
 
LVL 27

Assisted Solution

by:VBRocks
VBRocks earned 70 total points
ID: 18764318
Here's how you can do it with VB6, this will return a recordset for you to work with, let me know if you have VB.NET:

-Note that you have to add a reference to Microsoft ActiveX Data Objects Library:

Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command

Dim param1 as new ADODB.Parameter
Dim param2 as new ADODB.Parameter
Dim param3 as new ADODB.Parameter

Dim numRecs As Integer  'number of records affected

cn.ConnectionString = "Connection String"
cn.Open

cmd.ActiveConnection = cn
cmd.CommandText = "proc_get_order_details"
cmd.CommandType = adCmdStoredProc

'Create parameters for the stored procedure
Set param1= cmd.CreateParameter("@OrderNumber", adVarChar, adParamInput, 10, m_strOrderNumber)
Set param2 = cmd.CreateParameter("@Client", adVarChar, adParamInput, 50, m_strClient)
Set param3 = cmd.CreateParameter("@HiJump2Aggresso", adVarChar, adParamInput, 20, m_lngHighJumpToAgressoJobId)
     
'Add parameters to cmd object
cmd.Parameters.Append param1
cmd.Parameters.Append param2
cmd.Parameters.Append param3

     
'Execute the command and return a recordset
set rst = cmd.Execute(numRecs)

   If numRecs > 0 Then
      'process with your recordset (rst)...

   End If
     
'Close the connection
cn.Close
     
'Cleanup
Set cmd = Nothing

Hope that helps!
0
 

Author Comment

by:itortu
ID: 18767688
I got it to work doing it like this:

strSql = "proc_get_order_details '" & m_strOrderNumber & "', '" & m_strClient & "', " & m_lngHighJumpToAgressoJobId
Set rstSelect = m_cnnAgresso.Execute(strSql)


I was formating the string incorrectly.
0
 
LVL 13

Expert Comment

by:nike_golf
ID: 18770633
Glad it worked.

NG,
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access 2016 VB code 9 115
Sending a email via excel using vba 6 82
VBA: Select SQL query based on a config Sheet v2 11 44
clicking a shape in a frame array vb6 3 45
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question