Hi
I'm not sure what the best approach for this is:
I have a stored procedure which I would like to use to return several
output values instead of returning a recordset.
CREATE PROCEDURE Test (@param1 int, @param2 int OUTPUT, @param3 int
OUTPUT) AS
SELECT field2, field3 FROM Table WHERE field1 = @param1
I would like to return @param2 as field2 and @param3 as field3
How do I do this without using SELECT multiple times?
THanks in advance
Sam 6 42131
Samuel Hon wrote: Hi
I'm not sure what the best approach for this is:
I have a stored procedure which I would like to use to return several output values instead of returning a recordset.
CREATE PROCEDURE Test (@param1 int, @param2 int OUTPUT, @param3 int OUTPUT) AS SELECT field2, field3 FROM Table WHERE field1 = @param1
I would like to return @param2 as field2 and @param3 as field3
How do I do this without using SELECT multiple times?
THanks in advance
Sam
Did you try:
CREATE PROCEDURE Test (@param1 int, @param2 int OUTPUT, @param3 int OUTPUT)
AS SELECT @param2 = field2, @param3 = field3 FROM Table WHERE field1 = @param1
Joe
Samuel Hon (no*****@samuelhon.co.uk) writes: I'm not sure what the best approach for this is:
I have a stored procedure which I would like to use to return several output values instead of returning a recordset.
CREATE PROCEDURE Test (@param1 int, @param2 int OUTPUT, @param3 int OUTPUT) AS SELECT field2, field3 FROM Table WHERE field1 = @param1
I would like to return @param2 as field2 and @param3 as field3
How do I do this without using SELECT multiple times?
SELECT @param2 = field2, @param3 = field4 FROM tbl WHERE field = @param1
Note that this is only useful, if you know or can assume that the
SELECT returns only one row. If it returns more than one row, receiving
the data in output parameters is not a good idea. In that case you should
use a result set.
--
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
I tried that and got this message
"A SELECT statement that assigns a value to a variable must not be
combined with data-retrieval operations"
I must be doing something stupid
Erland Sommarskog <so****@algonet.se> wrote in message news:<Xn*********************@127.0.0.1>... Samuel Hon (no*****@samuelhon.co.uk) writes: I'm not sure what the best approach for this is:
I have a stored procedure which I would like to use to return several output values instead of returning a recordset.
CREATE PROCEDURE Test (@param1 int, @param2 int OUTPUT, @param3 int OUTPUT) AS SELECT field2, field3 FROM Table WHERE field1 = @param1
I would like to return @param2 as field2 and @param3 as field3
How do I do this without using SELECT multiple times?
SELECT @param2 = field2, @param3 = field4 FROM tbl WHERE field = @param1
Note that this is only useful, if you know or can assume that the SELECT returns only one row. If it returns more than one row, receiving the data in output parameters is not a good idea. In that case you should use a result set.
It seems that you have to assign all the values to parameters so I
cant do
SELECT @param2 = field2, field3 FROM tbl WHERE field = @param1
I have to do
SELECT @param2 = field2, @param3 = field3 FROM tbl WHERE field =
@param1
I dont need a recordset, just testing for existence of a record so the
where clause is a little more complex than I've shown
Thanks for the help
Erland Sommarskog <so****@algonet.se> wrote in message news:<Xn*********************@127.0.0.1>... Samuel Hon (no*****@samuelhon.co.uk) writes: I'm not sure what the best approach for this is:
I have a stored procedure which I would like to use to return several output values instead of returning a recordset.
CREATE PROCEDURE Test (@param1 int, @param2 int OUTPUT, @param3 int OUTPUT) AS SELECT field2, field3 FROM Table WHERE field1 = @param1
I would like to return @param2 as field2 and @param3 as field3
How do I do this without using SELECT multiple times?
SELECT @param2 = field2, @param3 = field4 FROM tbl WHERE field = @param1
Note that this is only useful, if you know or can assume that the SELECT returns only one row. If it returns more than one row, receiving the data in output parameters is not a good idea. In that case you should use a result set.
Samuel Hon (no*****@samuelhon.co.uk) writes: SELECT @param2 = field2, @param3 = field3 FROM tbl WHERE field = @param1
I dont need a recordset, just testing for existence of a record so the where clause is a little more complex than I've shown
In such case you should do:
CREATE PROCEDURE does_it_exist_sp @inputpar some_type,
@exists bit OUTPUT
SELECT @exists = CASE WHEN EXISTS (SELECT *
FROM tbl
WHERE col = @inputpar=
THEN 1
ELSE 0
END
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Thanks Erland
I'm returning a few fields about the exising record, hence the output params CREATE PROCEDURE does_it_exist_sp @inputpar some_type, @exists bit OUTPUT
SELECT @exists = CASE WHEN EXISTS (SELECT * FROM tbl WHERE col = @inputpar= THEN 1 ELSE 0 END This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stanley Sinclair |
last post by:
I have a need to return multiple result sets from a stored procedure.
Want that SP to call others to get the data.
Win2003, db2 8.1.5.
Can't figure out how to handle open cursors, and return...
|
by: Terentius Neo |
last post by:
Is it possible to combine (in DB2 UDB 8.1) a stored procedure and a
select statement? I mean something like this:
Select
c.number,
call procedure( c.number ) as list
from
table c
With best...
|
by: CSDunn |
last post by:
Hello,
I have a situation in which I need to address three SQL Server 2000
Stored Procedure parameters in the OnClick event of an Option Group.
The Option Group lives on an Access 2000 ADP form.
...
|
by: VM |
last post by:
I'm working on a win appication that is constantly querying a small-sized
DB. Until now, I've been using Selects from within my app but, all of a
sudden I remembered of an application I was...
|
by: Paul Aspinall |
last post by:
Hi
I have a Stored Proc in SQL server, which creates a record key when a record
is created.
I want to return the value back to my code, once the record has been
created.
I am using SQLHelper...
|
by: Ahmet Karaca |
last post by:
Hi.
myds.Reset();
mycommand.SelectCommand.CommandText=
"Select att1 from Ing as Ingredient, Pro as Product "+
"where Pro.ad='apple' and Pro.id=Ing.id";
mycommand.Fill(myds, "Product"); // Here...
|
by: rayone |
last post by:
Hi folks.
I need advice.
2 options, which do you think is the better option to
display/retrieve/report on the data.
Keep in mind reporting (Crystal), SQL Performance, VB Code, usability,...
|
by: jzogg7272 |
last post by:
In my code I am executing a stored procedure to do a single row insert.
I check the return value of the execution and I am getting -1, whereas
a few weeks ago it was returning 0. Actually, I found...
|
by: codefragment |
last post by:
Hi
I have a chunky bit of sql that I will want to call from a number of
places. It will return a
few thousand rows. Whats the best way of structuring this?
1) I initially thought of using...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |