Monday, February 20, 2012

problem with output SP that takes Input

Hello,
I am trying to run/test an SP in Query Analyzer. The SP takes an input
param and outputs a value. How do I set this up in QA? Here is the SP
CREATE proc sp_Company_Workshop_Exists
@.RecordID int,
@.WorkshopExists bit output
as
if exists (
select *
from Workshop a
inner join Subscriber b
on ( a.CoID = b.CoID and a.SubscrID = b.SubscrID )
where b.RecordID = @.RecordID
)
set @.WorkshopExists = 1
else
set @.WorkshopExists = 0
return
I tried the following but getting error -- 15367 is my input param:
declare @.c int
declare @.WorkshopExists int
exec @.c = sp_Company_Workshop_Exists 15367 = @.WorkshopExists output
print @.WorkshopExists
Any suggestions appreciated
Thanks,
RichYou had a missing comma in the execution of the proc. The working code (conv
erted to pubs database)
below. A couple of comments:
Having sp_ in beginning of procedure name is considered bad practice.
I suggest you match the datatype of the out parameter to the one in the call
ing batch.
CREATE proc #sp_Company_Workshop_Exists
@.RecordID int,
@.WorkshopExists bit output
as
if exists (
select *
from authors)
set @.WorkshopExists = 1
else
set @.WorkshopExists = 0
return
GO
declare @.c int
declare @.WorkshopExists int
exec @.c = #sp_Company_Workshop_Exists 15367, @.WorkshopExists output
print @.WorkshopExists
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Rich" <Rich@.discussions.microsoft.com> wrote in message
news:ECECE8A6-31A8-49C0-AF2F-54F45D1918A3@.microsoft.com...
> Hello,
> I am trying to run/test an SP in Query Analyzer. The SP takes an input
> param and outputs a value. How do I set this up in QA? Here is the SP
> CREATE proc sp_Company_Workshop_Exists
> @.RecordID int,
> @.WorkshopExists bit output
> as
> if exists (
> select *
> from Workshop a
> inner join Subscriber b
> on ( a.CoID = b.CoID and a.SubscrID = b.SubscrID )
> where b.RecordID = @.RecordID
> )
> set @.WorkshopExists = 1
> else
> set @.WorkshopExists = 0
> return
> I tried the following but getting error -- 15367 is my input param:
> declare @.c int
> declare @.WorkshopExists int
> exec @.c = sp_Company_Workshop_Exists 15367 = @.WorkshopExists output
> print @.WorkshopExists
> Any suggestions appreciated
> Thanks,
> Rich|||OK. I changed the setup and now seems to work:
declare @.WorkshopExistsB bit
exec sp_Company_Workshop_Exists 15367, @.WorkshopExists = @.WorkshopExistsB
output
print @.WorkshopExistsB
"Rich" wrote:

> Hello,
> I am trying to run/test an SP in Query Analyzer. The SP takes an input
> param and outputs a value. How do I set this up in QA? Here is the SP
> CREATE proc sp_Company_Workshop_Exists
> @.RecordID int,
> @.WorkshopExists bit output
> as
> if exists (
> select *
> from Workshop a
> inner join Subscriber b
> on ( a.CoID = b.CoID and a.SubscrID = b.SubscrID )
> where b.RecordID = @.RecordID
> )
> set @.WorkshopExists = 1
> else
> set @.WorkshopExists = 0
> return
> I tried the following but getting error -- 15367 is my input param:
> declare @.c int
> declare @.WorkshopExists int
> exec @.c = sp_Company_Workshop_Exists 15367 = @.WorkshopExists output
> print @.WorkshopExists
> Any suggestions appreciated
> Thanks,
> Rich|||Yes, I am aware of the "Bad Practice". Not to pass the buck, but I am takin
g
over for a young man who has moved on to bigger and better things. So I wil
l
have to deal with his youthful exuberance, this being one of them. The kid
is very smart, just out of college. He just needs to refine a few things,
just like me :).
Anyway, thank you for your reply and example.
Rich
"Tibor Karaszi" wrote:

> You had a missing comma in the execution of the proc. The working code (co
nverted to pubs database)
> below. A couple of comments:
> Having sp_ in beginning of procedure name is considered bad practice.
> I suggest you match the datatype of the out parameter to the one in the ca
lling batch.
> CREATE proc #sp_Company_Workshop_Exists
> @.RecordID int,
> @.WorkshopExists bit output
> as
> if exists (
> select *
> from authors)
> set @.WorkshopExists = 1
> else
> set @.WorkshopExists = 0
> return
> GO
> declare @.c int
> declare @.WorkshopExists int
> exec @.c = #sp_Company_Workshop_Exists 15367, @.WorkshopExists output
> print @.WorkshopExists
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Rich" <Rich@.discussions.microsoft.com> wrote in message
> news:ECECE8A6-31A8-49C0-AF2F-54F45D1918A3@.microsoft.com...
>

No comments:

Post a Comment