dbTalk Databases Forums  

Collecting a value returned from a stored procedure with the RETURN keyword

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Collecting a value returned from a stored procedure with the RETURN keyword in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Hemraj Julha
 
Posts: n/a

Default Collecting a value returned from a stored procedure with the RETURN keyword - 01-03-2004 , 05:44 AM






Hi All

Happy New Year.

Inside a DTS package I have to implement a functionality that will enable me
create and entry in a table and then collect the identity column generated.
I have the following statements in the SQL Task.


DECLARE @newID
EXEC @newID = ps_AddDemoDTS03Control ?, ?
SELECT @newID

The idea is to set the two arguments from global variables and collect the
return value in gobal varuable.

However, when I click on the parameters button I get the error message:

Package Error
Error source: Microsoft OLE DB Provider for SQL Server
Error Description: Syntax Error or access violation

Parsing SQL Statement

An error occurred while parsing SQL Statement for parameters. Please check
the syntax of teh SQL statement and verify that it is valid for the
connection selected.

The code of the stored procedure is

CREATE PROCEDURE ps_AddDemoDTS03Control (@dataloadid, @status varchar(50)
AS
SET NOCOUNT ON
DECLARE @newid int
insert into table1(dataloadid, status) select @dataloadid, @status
SELECT @newid = @@IDENTITY
RETURN @newid

I could use a third paramter as output in the stored procedure but I prefer
using the return method, specially when used in a VB program.

Can someone shed some light on this and show how to collect return
parameters from a stored procedure.

Thanks

Raj



Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Collecting a value returned from a stored procedure with the RETURN keyword - 01-03-2004 , 05:52 AM






try:

DECLARE @newID
EXEC @newID = ps_AddDemoDTS03Control ?, ?
SELECT @newID as ValueReturned


--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Hemraj Julha" <hjulha (AT) intnet (DOT) mu> wrote

Quote:
Hi All

Happy New Year.

Inside a DTS package I have to implement a functionality that will enable
me
create and entry in a table and then collect the identity column
generated.
I have the following statements in the SQL Task.


DECLARE @newID
EXEC @newID = ps_AddDemoDTS03Control ?, ?
SELECT @newID

The idea is to set the two arguments from global variables and collect the
return value in gobal varuable.

However, when I click on the parameters button I get the error message:

Package Error
Error source: Microsoft OLE DB Provider for SQL Server
Error Description: Syntax Error or access violation

Parsing SQL Statement

An error occurred while parsing SQL Statement for parameters. Please check
the syntax of teh SQL statement and verify that it is valid for the
connection selected.

The code of the stored procedure is

CREATE PROCEDURE ps_AddDemoDTS03Control (@dataloadid, @status varchar(50)
AS
SET NOCOUNT ON
DECLARE @newid int
insert into table1(dataloadid, status) select @dataloadid, @status
SELECT @newid = @@IDENTITY
RETURN @newid

I could use a third paramter as output in the stored procedure but I
prefer
using the return method, specially when used in a VB program.

Can someone shed some light on this and show how to collect return
parameters from a stored procedure.

Thanks

Raj





Reply With Quote
  #3  
Old   
Hemraj Julha
 
Posts: n/a

Default Re: Collecting a value returned from a stored procedure with the RETURN keyword - 01-03-2004 , 06:00 AM



Thanks for the quick reply Allan. But ...
I still get the error message. I have SQL 2000 with service pack 3. Any
clues ?

Raj

"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote

Quote:
try:

DECLARE @newID
EXEC @newID = ps_AddDemoDTS03Control ?, ?
SELECT @newID as ValueReturned


--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Hemraj Julha" <hjulha (AT) intnet (DOT) mu> wrote in message
news:%23rCDo6e0DHA.1736 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi All

Happy New Year.

Inside a DTS package I have to implement a functionality that will
enable
me
create and entry in a table and then collect the identity column
generated.
I have the following statements in the SQL Task.


DECLARE @newID
EXEC @newID = ps_AddDemoDTS03Control ?, ?
SELECT @newID

The idea is to set the two arguments from global variables and collect
the
return value in gobal varuable.

However, when I click on the parameters button I get the error message:

Package Error
Error source: Microsoft OLE DB Provider for SQL Server
Error Description: Syntax Error or access violation

Parsing SQL Statement

An error occurred while parsing SQL Statement for parameters. Please
check
the syntax of teh SQL statement and verify that it is valid for the
connection selected.

The code of the stored procedure is

CREATE PROCEDURE ps_AddDemoDTS03Control (@dataloadid, @status
varchar(50)
AS
SET NOCOUNT ON
DECLARE @newid int
insert into table1(dataloadid, status) select @dataloadid, @status
SELECT @newid = @@IDENTITY
RETURN @newid

I could use a third paramter as output in the stored procedure but I
prefer
using the return method, specially when used in a VB program.

Can someone shed some light on this and show how to collect return
parameters from a stored procedure.

Thanks

Raj







Reply With Quote
  #4  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Collecting a value returned from a stored procedure with the RETURN keyword - 01-03-2004 , 06:58 AM



I did this

CREATE PROCEDURE ReturnValueSimple
AS
SET NOCOUNT ON
RETURN 10
go

In my ExecuteSQL task I did

DECLARE @val int
Exec @val = ReturnValueSimple
SELECT @Val as Value

I cliked the parameters button and assigned the value to a Row Value output.

SQL Server 2000 SP3 + Sec hotfixes.


Now to take two input values and add a return value

CREATE PROCEDURE ReturnValueSimpleWithInputs @input1 int, @input2 int
AS
SET NOCOUNT ON
RETURN @input1 + @input2
go


Here we are going to cheat.

The design time parser is not as advanced or forgiving as its runtime
counterpart so what are going to do is fool it by creating the same metadata
but not the same statement.

I enter into the ExecuteSQL task the following

SELECT id AS OutputTest FROM sysobjects where id = ? OR id = ?I can now map
my parametersI go to Disconnected edit (Or the object model in an Active
Script task) and enter my real statement. DECLARE @val intExec @val =
ReturnValueSimpleWithInputs ?,?select @val as OutputTestWorks like a
charm.We discuss it more hereGlobal Variables and Stored Procedure
Parameters(http://www.sqldts.com/Default.aspx?234)





--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Hemraj Julha" <hjulha (AT) intnet (DOT) mu> wrote

Quote:
Thanks for the quick reply Allan. But ...
I still get the error message. I have SQL 2000 with service pack 3. Any
clues ?

Raj

"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:ezctU#e0DHA.556 (AT) TK2MSFTNGP11 (DOT) phx.gbl...
try:

DECLARE @newID
EXEC @newID = ps_AddDemoDTS03Control ?, ?
SELECT @newID as ValueReturned


--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Hemraj Julha" <hjulha (AT) intnet (DOT) mu> wrote in message
news:%23rCDo6e0DHA.1736 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi All

Happy New Year.

Inside a DTS package I have to implement a functionality that will
enable
me
create and entry in a table and then collect the identity column
generated.
I have the following statements in the SQL Task.


DECLARE @newID
EXEC @newID = ps_AddDemoDTS03Control ?, ?
SELECT @newID

The idea is to set the two arguments from global variables and collect
the
return value in gobal varuable.

However, when I click on the parameters button I get the error
message:

Package Error
Error source: Microsoft OLE DB Provider for SQL Server
Error Description: Syntax Error or access violation

Parsing SQL Statement

An error occurred while parsing SQL Statement for parameters. Please
check
the syntax of teh SQL statement and verify that it is valid for the
connection selected.

The code of the stored procedure is

CREATE PROCEDURE ps_AddDemoDTS03Control (@dataloadid, @status
varchar(50)
AS
SET NOCOUNT ON
DECLARE @newid int
insert into table1(dataloadid, status) select @dataloadid, @status
SELECT @newid = @@IDENTITY
RETURN @newid

I could use a third paramter as output in the stored procedure but I
prefer
using the return method, specially when used in a VB program.

Can someone shed some light on this and show how to collect return
parameters from a stored procedure.

Thanks

Raj









Reply With Quote
  #5  
Old   
Hemraj Julha
 
Posts: n/a

Default Re: Collecting a value returned from a stored procedure with the RETURN keyword - 01-03-2004 , 12:31 PM



Thanks, it works now.

Raj




"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote

Quote:
I did this

CREATE PROCEDURE ReturnValueSimple
AS
SET NOCOUNT ON
RETURN 10
go

In my ExecuteSQL task I did

DECLARE @val int
Exec @val = ReturnValueSimple
SELECT @Val as Value

I cliked the parameters button and assigned the value to a Row Value
output.

SQL Server 2000 SP3 + Sec hotfixes.


Now to take two input values and add a return value

CREATE PROCEDURE ReturnValueSimpleWithInputs @input1 int, @input2 int
AS
SET NOCOUNT ON
RETURN @input1 + @input2
go


Here we are going to cheat.

The design time parser is not as advanced or forgiving as its runtime
counterpart so what are going to do is fool it by creating the same
metadata
but not the same statement.

I enter into the ExecuteSQL task the following

SELECT id AS OutputTest FROM sysobjects where id = ? OR id = ?I can now
map
my parametersI go to Disconnected edit (Or the object model in an Active
Script task) and enter my real statement. DECLARE @val intExec @val =
ReturnValueSimpleWithInputs ?,?select @val as OutputTestWorks like a
charm.We discuss it more hereGlobal Variables and Stored Procedure
Parameters(http://www.sqldts.com/Default.aspx?234)





--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Hemraj Julha" <hjulha (AT) intnet (DOT) mu> wrote in message
news:uzBFVDf0DHA.2324 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Thanks for the quick reply Allan. But ...
I still get the error message. I have SQL 2000 with service pack 3. Any
clues ?

Raj

"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:ezctU#e0DHA.556 (AT) TK2MSFTNGP11 (DOT) phx.gbl...
try:

DECLARE @newID
EXEC @newID = ps_AddDemoDTS03Control ?, ?
SELECT @newID as ValueReturned


--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Hemraj Julha" <hjulha (AT) intnet (DOT) mu> wrote in message
news:%23rCDo6e0DHA.1736 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi All

Happy New Year.

Inside a DTS package I have to implement a functionality that will
enable
me
create and entry in a table and then collect the identity column
generated.
I have the following statements in the SQL Task.


DECLARE @newID
EXEC @newID = ps_AddDemoDTS03Control ?, ?
SELECT @newID

The idea is to set the two arguments from global variables and
collect
the
return value in gobal varuable.

However, when I click on the parameters button I get the error
message:

Package Error
Error source: Microsoft OLE DB Provider for SQL Server
Error Description: Syntax Error or access violation

Parsing SQL Statement

An error occurred while parsing SQL Statement for parameters. Please
check
the syntax of teh SQL statement and verify that it is valid for the
connection selected.

The code of the stored procedure is

CREATE PROCEDURE ps_AddDemoDTS03Control (@dataloadid, @status
varchar(50)
AS
SET NOCOUNT ON
DECLARE @newid int
insert into table1(dataloadid, status) select @dataloadid, @status
SELECT @newid = @@IDENTITY
RETURN @newid

I could use a third paramter as output in the stored procedure but I
prefer
using the return method, specially when used in a VB program.

Can someone shed some light on this and show how to collect return
parameters from a stored procedure.

Thanks

Raj











Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.