[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

use stored procedure from inside program

Posted on 2007-03-20
5
Medium Priority
?
219 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Suggested Courses

649 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