Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Yet Another Stored Procedure Question

by LanceDeeply (Chaplain)
on Jun 24, 2003 at 14:37 UTC ( [id://268525]=note: print w/replies, xml ) Need Help??


in reply to Yet Another Stored Procedure Question

given the table:
CREATE TABLE dbo.TestIds ( TestID int not null, TestName varchar(50) not null )

and stored proc w/ out parameter:
create proc dbo.GetTest( @pName varchar(50) = '', @pID int = 0 out ) as set nocount on begin select @pID = TestID from TestIds where TestName = @pName if ( @@rowcount = 0 ) begin select @pID = isnull(max(TestID),0) + 1 from TestIDs insert TestIDs select TestID = @pID, TestName = @pName end end

you can do this:
my $sql = ' declare @id int exec GetTest ?, @id out select GotID = @id '; my $sth = $dbh->prepare($sql); if ( $sth->execute('foo') ) { while (my $hash = $sth->fetchrow_hashref ) { foreach my $key (keys %$hash) { print $key . " => " . $$hash{$ +key} . "\n" if $$hash{$key}; }; } }

to get this output:
GotID => 2

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://268525]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 16:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found