CREATE TABLE dbo.TestIds ( TestID int not null, TestName varchar(50) not null ) #### 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 #### 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}; }; } } #### GotID => 2