Hi All
Im generally a vb programmer and am used to referencing multiple records
returned from a query performed on an sql database and im trying to move
some functions of my software into sql stored procedures. So far ive been
able to move the functions relatively easily but im unsure about how to
output multiple values from an sql stored procedure. By this i mean for
example one of the stored procedures may take your username and return the
contents of a single field in a record of one of the tables, but i would
like to be able to return for arguement sake the contents of a single field
from two records if possible. Under VB im used to referencing the recordset
with a (1) after it to reference the corresponding record from the query. I
was wondering if there is a way to do something similar to this with stored
procedures if possible ?
Thanks for any help 15 6012
Jarrod Morrison (ja*****@ihug.c om.au) writes: Im generally a vb programmer and am used to referencing multiple records returned from a query performed on an sql database and im trying to move some functions of my software into sql stored procedures. So far ive been able to move the functions relatively easily but im unsure about how to output multiple values from an sql stored procedure. By this i mean for example one of the stored procedures may take your username and return the contents of a single field in a record of one of the tables, but i would like to be able to return for arguement sake the contents of a single field from two records if possible. Under VB im used to referencing the recordset with a (1) after it to reference the corresponding record from the query. I was wondering if there is a way to do something similar to this with stored procedures if possible ?
Unfortunately, without an example, I find it difficult to get a clear
understanding of what you are doing.
However, a general word of caution: SQL is a very different language
than Basic with different mindsets. Translating VB into SQL line by
line, may not always be the best approach.
Since I don't know what you are doing, this link may be completely
irrelevant. But maybe it addresses something of what you are trying to
do: http://www.algonet.se/~sommar/share_data.html.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Hi Erland
Thankyou for the link, it sort of helped me a little bit, but I thought I
would give you a direct example of what I am doing to see if you can give me
any further pointers on what I can do. In my stored procedure I will execute
a query and store the results in a temporary table in the procedure. An
Example of what will be in the table is as follows:
PrinterPath Name Priority
\\Server1\Print er1 Printer 1 1
\\Server2\Print er2 Printer 2 2
What I want to do is to output only the first columns data from the
procedure to my vb client program (IE: \\Server1\Print er1 and
\\Server2\Print er2). Obviously this is a basic example and the amount of
data and records will change all the time. To begin with I only want to
output the first column, but if possible down the track I would also like to
do multiple columns if it is possible. At the moment in my other stored
procedures I am just defining a variable at the beginning of the procedure
as output and assigning a value to it before the procedure ends. I am hoping
there is an easy way to output multiple values from the stored procedure in
a similar fashion.
Thanks for all your help
"Erland Sommarskog" <so****@algonet .se> wrote in message
news:Xn******** *************@1 27.0.0.1... Unfortunately, without an example, I find it difficult to get a clear understanding of what you are doing.
However, a general word of caution: SQL is a very different language than Basic with different mindsets. Translating VB into SQL line by line, may not always be the best approach.
Since I don't know what you are doing, this link may be completely irrelevant. But maybe it addresses something of what you are trying to do: http://www.algonet.se/~sommar/share_data.html.
-- Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Jarrod Morrison (ja*****@ihug.c om.au) writes: Example of what will be in the table is as follows:
PrinterPath Name Priority
\\Server1\Print er1 Printer 1 1 \\Server2\Print er2 Printer 2 2
What I want to do is to output only the first columns data from the procedure to my vb client program (IE: \\Server1\Print er1 and \\Server2\Print er2). Obviously this is a basic example and the amount of data and records will change all the time. To begin with I only want to output the first column, but if possible down the track I would also like to do multiple columns if it is possible.
SELECT PrinterPath FROM tbl WHERE ...
SELECT PrinterPath, Name FROM tbl WHERE ...
Then in VB you receive the values in a recordset.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Hi Erland
Do you mean to do the select statement straight from the vb program ? Or
just plain do the select statement in the stored procedure on the sql server
and vb program will receieve it as a recordset ? I dont really understand
what you meant there as i was trying to do all the work in the sql stored
procedure if possible and just return the results
Thanks
"Erland Sommarskog" <so****@algonet .se> wrote in message
news:Xn******** **************@ 127.0.0.1... Jarrod Morrison (ja*****@ihug.c om.au) writes: Example of what will be in the table is as follows:
PrinterPath Name Priority
\\Server1\Print er1 Printer 1 1 \\Server2\Print er2 Printer 2 2
What I want to do is to output only the first columns data from the procedure to my vb client program (IE: \\Server1\Print er1 and \\Server2\Print er2). Obviously this is a basic example and the amount of data and records will change all the time. To begin with I only want to output the first column, but if possible down the track I would also like to do multiple columns if it is possible.
SELECT PrinterPath FROM tbl WHERE ...
SELECT PrinterPath, Name FROM tbl WHERE ...
Then in VB you receive the values in a recordset.
-- Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Jarrod Morrison (ja*****@ihug.c om.au) writes: Do you mean to do the select statement straight from the vb program ? Or just plain do the select statement in the stored procedure on the sql server and vb program will receieve it as a recordset ? I dont really understand what you meant there as i was trying to do all the work in the sql stored procedure if possible and just return the results
I was thinking of something like:
CREATE PROCEDURE your_sp AS
SELECT PrinterPath, Name FROM tbl WHERE...
I'm sorry if my answers are not fully clear, but I have a feeling that
there something hiding in your questions that I have not been able to
grasp.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Hi
This is my interpretation By this i mean for example one of the stored procedures may take your username and return the contents of a single field in a record of one of the tables,
1 - You have a fixed number of output parameters from the stored
procedure
Dim objConn as ADODB.Connectio n
Dim objCmd As ADODB.Command
Dim objRst As ADODB.Recordset
Dim objField As ADODB.Field
'Open your connection first
'Open command
Set objCmd = New ADODB.Command
objCmd.CommandT ype = adCmdStoredProc
objCmd.CommandT ext = "spGetParen ts"
Set objCmd.ActiveCo nnection = objConn
'Add your input and output parameters
objCmd.Paramete rs.Append objCmd.CreatePa rameter("UserNa me",
adVarChar, adParamInput, 8, strUserName)
objCmd.Paramete rs.Append objCmd.CreatePa rameter("Father ",
adVarChar, adParamOutput, 50)
objCmd.Paramete rs.Append objCmd.CreatePa rameter("Mother ",
adVarChar, adParamOutput, 50)
'Execute
objCmd.Execute
'Get your parameters back out
strFather = objCmd.Paramete rs("Father").Va lue
strMother = objCmd.Paramete rs("Mother").Va lue
2 - You need to retrieve a number of records from one field.
but i would like to be able to return for arguement sake the contents of a single field from two records if possible. Under VB im used to referencing the recordset with a (1) after it to reference the corresponding record from the query. I was wondering if there is a way to do something similar to this with stored procedures if possible ?
'Open command
Set objCmd = New ADODB.Command
objCmd.CommandT ype = adCmdStoredProc
objCmd.CommandT ext = "spGetParen ts"
Set objCmd.ActiveCo nnection = objConn
'Add your input and output parameters
objCmd.Paramete rs.Append objCmd.CreatePa rameter("UserNa me",
adVarChar, adParamInput, 8, strUserName)
'Execute
Set objRst = objCmd.Execute
'Get the field. For large recordsets, this is the best approach
'See http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=265
'You can use (1) here if you'd like
'Set objField = objRst.Fields(1 )
Set objField = objRst.Fields(" YourField")
'Get your values from the recordset
Do Until objRst.EOF
Debug.Print objField.Value
objRst.MoveNext
Loop
objRst.Close
Set objRst = Nothing
I hope this is what you're looking for
Hi Samuel
Thanks for the post, thats exactly what i wanted. But i have one further
question about the second part of the post, when i execute the select
statement inside the stored procedure it is actually part of a loop and thus
each select statement is being treated seperately by VB, so if i use query
analyzer i see for example 3 seperate returns which is ok because it is what
is meant to be returned, however vb is only reading the first one of these
returns and then closing the recordset. Im sure there is an easy way around
this but im unsure of what to do. Any help is greatly appreciated
Thanks
"Samuel Hon" <no*****@samuel hon.co.uk> wrote in message
news:c8******** *************** ***@posting.goo gle.com... Hi
This is my interpretation
By this i mean for example one of the stored procedures may take your username and return the contents of a single field in a record of one of the tables,
1 - You have a fixed number of output parameters from the stored procedure
Dim objConn as ADODB.Connectio n Dim objCmd As ADODB.Command Dim objRst As ADODB.Recordset Dim objField As ADODB.Field
'Open your connection first
'Open command Set objCmd = New ADODB.Command objCmd.CommandT ype = adCmdStoredProc objCmd.CommandT ext = "spGetParen ts" Set objCmd.ActiveCo nnection = objConn
'Add your input and output parameters objCmd.Paramete rs.Append objCmd.CreatePa rameter("UserNa me", adVarChar, adParamInput, 8, strUserName) objCmd.Paramete rs.Append objCmd.CreatePa rameter("Father ", adVarChar, adParamOutput, 50) objCmd.Paramete rs.Append objCmd.CreatePa rameter("Mother ", adVarChar, adParamOutput, 50)
'Execute objCmd.Execute
'Get your parameters back out strFather = objCmd.Paramete rs("Father").Va lue strMother = objCmd.Paramete rs("Mother").Va lue 2 - You need to retrieve a number of records from one field.
but i would like to be able to return for arguement sake the contents of a single field from two records if possible. Under VB im used to referencing the recordset with a (1) after it to reference the corresponding record from the query. I was wondering if there is a way to do something similar to this with stored procedures if possible ?
'Open command Set objCmd = New ADODB.Command objCmd.CommandT ype = adCmdStoredProc objCmd.CommandT ext = "spGetParen ts" Set objCmd.ActiveCo nnection = objConn
'Add your input and output parameters objCmd.Paramete rs.Append objCmd.CreatePa rameter("UserNa me", adVarChar, adParamInput, 8, strUserName)
'Execute Set objRst = objCmd.Execute
'Get the field. For large recordsets, this is the best approach 'See http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=265 'You can use (1) here if you'd like 'Set objField = objRst.Fields(1 ) Set objField = objRst.Fields(" YourField")
'Get your values from the recordset Do Until objRst.EOF Debug.Print objField.Value objRst.MoveNext Loop
objRst.Close Set objRst = Nothing
I hope this is what you're looking for
Hi Erland
Thanks for all your help with the stored procedure questions, Samuel replied
to the posts as well and gave me a good vb example to go with and now it
seems like it is all working well. Thanks again
"Erland Sommarskog" <so****@algonet .se> wrote in message
news:Xn******** **************@ 127.0.0.1... Jarrod Morrison (ja*****@ihug.c om.au) writes: Do you mean to do the select statement straight from the vb program ? Or just plain do the select statement in the stored procedure on the sql server and vb program will receieve it as a recordset ? I dont really understand what you meant there as i was trying to do all the work in the sql stored procedure if possible and just return the results
I was thinking of something like:
CREATE PROCEDURE your_sp AS SELECT PrinterPath, Name FROM tbl WHERE...
I'm sorry if my answers are not fully clear, but I have a feeling that there something hiding in your questions that I have not been able to grasp.
-- Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Not sure I understand your question exactly, but it sounds like maybe
you need the ADO .NextRecordset method, which does just what it sounds
like, brings back the next recordset from your stored procedure.
On Sun, 14 Dec 2003 16:01:21 +1100, "Jarrod Morrison"
<ja*****@ihug.c om.au> wrote: Hi Samuel
Thanks for the post, thats exactly what i wanted. But i have one further question about the second part of the post, when i execute the select statement inside the stored procedure it is actually part of a loop and thus each select statement is being treated seperately by VB, so if i use query analyzer i see for example 3 seperate returns which is ok because it is what is meant to be returned, however vb is only reading the first one of these returns and then closing the recordset. Im sure there is an easy way around this but im unsure of what to do. Any help is greatly appreciated
Thanks
"Samuel Hon" <no*****@samuel hon.co.uk> wrote in message news:c8******* *************** ****@posting.go ogle.com... Hi
This is my interpretation
> By this i > mean for example one of the stored procedures may take your username and > return the contents of a single field in a record of one of the tables,
1 - You have a fixed number of output parameters from the stored procedure
Dim objConn as ADODB.Connectio n Dim objCmd As ADODB.Command Dim objRst As ADODB.Recordset Dim objField As ADODB.Field
'Open your connection first
'Open command Set objCmd = New ADODB.Command objCmd.CommandT ype = adCmdStoredProc objCmd.CommandT ext = "spGetParen ts" Set objCmd.ActiveCo nnection = objConn
'Add your input and output parameters objCmd.Paramete rs.Append objCmd.CreatePa rameter("UserNa me", adVarChar, adParamInput, 8, strUserName) objCmd.Paramete rs.Append objCmd.CreatePa rameter("Father ", adVarChar, adParamOutput, 50) objCmd.Paramete rs.Append objCmd.CreatePa rameter("Mother ", adVarChar, adParamOutput, 50)
'Execute objCmd.Execute
'Get your parameters back out strFather = objCmd.Paramete rs("Father").Va lue strMother = objCmd.Paramete rs("Mother").Va lue 2 - You need to retrieve a number of records from one field.
> but i would like to be able to return for arguement sake the contents of > a single field from two records if possible. Under VB im used to > referencing the recordset with a (1) after it to reference the > corresponding record from the query. I was wondering if there is a way > to do something similar to this with stored procedures if possible ?
'Open command Set objCmd = New ADODB.Command objCmd.CommandT ype = adCmdStoredProc objCmd.CommandT ext = "spGetParen ts" Set objCmd.ActiveCo nnection = objConn
'Add your input and output parameters objCmd.Paramete rs.Append objCmd.CreatePa rameter("UserNa me", adVarChar, adParamInput, 8, strUserName)
'Execute Set objRst = objCmd.Execute
'Get the field. For large recordsets, this is the best approach 'See http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=265 'You can use (1) here if you'd like 'Set objField = objRst.Fields(1 ) Set objField = objRst.Fields(" YourField")
'Get your values from the recordset Do Until objRst.EOF Debug.Print objField.Value objRst.MoveNext Loop
objRst.Close Set objRst = Nothing
I hope this is what you're looking for This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: sedefo |
last post by:
I ran into this Microsoft Patterns & Practices Enterprise Library while i
was researching how i can write a database independent data access layer. In
my company we already use Data Access Application Block (DAAB) in our .Net
projects. We use SqlHelper in SQL based projects, and OracleHelper in Oracle
based ones. OracleHelper was not published officially by Microsoft as part of
the DAAB but it was given as a helper code in a sample .Net...
|
by: pmud |
last post by:
Hi,
I need to display columns in a data grid based on 7 different queries. Now I
have 32 questions:
1. Is it possble to have 1 single data adapter with 7 queries & 1 data set
or do I need to have a separate data adapter & a separate data set for each
select query?
If thats possible then how?
|
by: kjphipps_377 |
last post by:
Hi all!
I have an application that needs to copy the database structure from
one database to another without using the "Generate SQL Script"
function in Enterprise Manager. I'd like to do this from within a
stored procedure. Can someone recommend the best approach for this?
I've seen references to using SQL-DMO from a stored procedure using the
sp_OA* procs in other postings to this group but was wondering if there
was an easier way?...
|
by: Josh Strickland |
last post by:
I am attempting to create an Access database which uses forms to enter
data. The issue I am having is returning the query results from the
Stored Procedure back in to the Access Form.
tCetecM1CUST (SQL Table that contains the Customer Information)
tAccountingDetail (SQL Table that contains the information in the
form)
frmAccountingEntry (Access form used to enter data)
spGetCustomerInformation (Stored Procedure which returns data using...
|
by: Wojciech Wendrychowicz |
last post by:
Hello to All,
I'm trying to retrieve records from AS/400 in an VBA application.
So, I've made an RPG program, then a stored procedure wchich calls that RPG
program, and finally some VBA code to call the stored procedure and retrieve
data from AS/400.
The problem is, that when I finally run my VB code, it just hangs.
But when I call the same stored procedure from "pure" SQL - it works
perfect. (I evaluate Aqua Data Studio 3.7)
What I...
| |
by: David Lozzi |
last post by:
Hello,
I have a proc as displayed below. When I try to run it from ASP.NET I get an
error.
CREATE PROCEDURE .
@SID as int,
@EID as int,
@DID as int,
@StartTime as varchar(10),
|
by: deepdata |
last post by:
Hi,
I am trying to fetch data from db2 (express version) database by
calling stored procedure. I have tried to use both cursor and for loop
but still i am getting error.
--======Start procedure=============
Create PROCEDURE get_timedout_scripts
(
|
by: Roger |
last post by:
I have a stored procedure running on DB2 V7 Z/os calling a COBOL
program to do some inserts. The stored procedure have 3 input columns
and one column is of varchar(32648)
The stored procedure is being called from a V7 DB2 connect client.
The stored procedure is giving SQL0104N An unexpected token was found
if my varchar data goes beyond 1024 bytes. Anything under 1025 bytes
on that column is working perfectly.
Does anybody know of...
|
by: preejith |
last post by:
Error Code : 1329, No data - zero rows fetched, selected, or processed. MYSQL
I am getting the following error while running a stored procedure in mysql5.0
Error Code : 1329
No data - zero rows fetched, selected, or processed.
I have an stored procedure SP1 which calls stored procedure SP2 and SP2 calls a function F1.
I have run this script from .bat file.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |