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