cpryce wrote:
> I apologize for the Off-topic Question.
>
> I have an application that was built in Perl for MySQL. I want to
port the
> application to an MS SQL server, but there doesn't seem to be an
equivalent
> to the LAST_INSERT_ID function.
>
> Is there a Transact equivalent, or does any one have experience coding a
> work-around?
not sure if this is the same thing you're referring to - @@identity
returns the value of the automatically generated id. here is a sample
of how i use it:
--snip--
# set up a query
# THIS IS NOT PORTABLE SQL. @@identity is specific to MSSQL(2000)
# Note that FreeTDS and DBD::Sybase do not support placeholders
my $query = qq{
INSERT INTO item (
location,
type,
cost,
purchase_date,
vendor
)
VALUES ('$location_id', '$type', $cost, '$purchasedate',
'$vendor');
SELECT \@\@identity
};
eval {
my $sth = $MSDBH->prepare($query);
$sth->execute;
($uid) = $sth->fetchrow_array;
};
if ($@) {
# caller handles error
die $@;
}
return $uid;
--snip--
'hope that helps.
cheers,
twkonefal
===
--
"The stuff you own ends up owning you ... It's only after you've lost
everything that you're free to do anything." --tyler durden
New Media Copyright Extensions Would Harm Canada:
http://ansuz.sooke.bc.ca/icsub.html