?
Solved

Using a VB SCript to call Sql View with Parameter

Posted on 2011-10-10
4
Medium Priority
?
389 Views
Last Modified: 2012-05-12
I have a view..VWOpenOrders...

.SELECT     SUM(SorDetail.MOrderQty * SorDetail.MPrice) AS Line, ArCustomer.Name
FROM         SorMaster INNER JOIN
                      ArCustomer ON SorMaster.Customer = ArCustomer.Customer LEFT OUTER JOIN
                      SorDetail ON SorMaster.SalesOrder = SorDetail.SalesOrder
WHERE     (SorMaster.OrderStatus <> '9')
GROUP BY  ArCustomer.Name...

and the Corresponding VB Script is

dim objConnection, objRecordSet

Set objConnection = CreateObject("ADODB.Connection")

Set objRecordSet = CreateObject("ADODB.Recordset")
 

objConnection.Open = "Provider=SQLOLEDB;Data Source=VMXP-SYSSQL08;Initial Catalog=SysproOutdoors;User ID=sa;pwd=100399"

objRecordSet.Open "select Name,Line from VWOpenOrders", objConnection, adOpenStatic, adLockOptimistic


How can i have a parameter field based on entry for ArCustomer.Name
0
Comment
Question by:Mikeyman_01
  • 3
4 Comments
 
LVL 7

Expert Comment

by:mozcullu
ID: 36942362
dim objConnection, objRecordSet, tparameter

Set objConnection = CreateObject("ADODB.Connection")

Set objRecordSet = CreateObject("ADODB.Recordset")

tparameter=""

objConnection.Open = "Provider=SQLOLEDB;Data Source=VMXP-SYSSQL08;Initial Catalog=SysproOutdoors;User ID=sa;pwd=100399"

objRecordSet.Open "select Name,Line from VWOpenOrders", objConnection, adOpenStatic, adLockOptimistic

objRecordSet.Open "select Name,Line from VWOpenOrders where ArCustomer.Name='"&tparameter&"', objConnection, adOpenStatic, adLockOptimistic
0
 
LVL 7

Expert Comment

by:mozcullu
ID: 36942383
last line should be

objRecordSet.Open "select Name,Line from VWOpenOrders where ArCustomer.Name='"&tparameter&"'", objConnection, adOpenStatic, adLockOptimistic
0
 

Author Comment

by:Mikeyman_01
ID: 36946054
I am getting an error that says  'Operaion is not allowed when the object is open'

Any thoughts??
0
 
LVL 7

Accepted Solution

by:
mozcullu earned 2000 total points
ID: 36948421
sorry my fault try this

dim objConnection, objRecordSet, tparameter

Set objConnection = CreateObject("ADODB.Connection")

Set objRecordSet = CreateObject("ADODB.Recordset")

tparameter=""

objConnection.Open = "Provider=SQLOLEDB;Data Source=VMXP-SYSSQL08;Initial Catalog=SysproOutdoors;User ID=sa;pwd=100399
objRecordSet.Open "select Name,Line from VWOpenOrders where ArCustomer.Name='"&tparameter&"'", objConnection, adOpenStatic, adLockOptimistic
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

840 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