Solved

use stored procedure from inside program

Posted on 2007-03-20
5
196 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now