?
Solved

use stored procedure from inside program

Posted on 2007-03-20
5
Medium Priority
?
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
nike_golf earned 720 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 280 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

762 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