2ge has asked for the wisdom of the Perl Monks concerning the following question:

Hi again,

it is possible to know how many columns, name of those columns, and also data types return stored procedure in MSSQL ? Now I am parsing T-SQL stored procedure, but it seems it is not simple task to do that good. For my work is enough, if I get somehow names of all columns, thats all. I connect to MSSQL with this snippet:
use strict; use warnings; use DBI; my $dsn = 'DBI:ODBC:MSSQL'; my $user = 'user'; my $auth = 'pass'; my $dbh = DBI->connect($dsn, $user, $auth, { RaiseError => 1, AutoComm +it => 1} my $sth = $dbh->prepare_cached("execute stored_procedure");

now, how I can determine names of columns? Any help helps :)
--
Brano

Replies are listed 'Best First'.
Re: MSSQL, SP, Columns and datatypes
by Arunbear (Prior) on Nov 08, 2004 at 14:15 UTC
    This should give you the column names:
    my @col_names = keys %{$sth->fetchrow_hashref};
    or
    my @col_names = @{$sth->{NAME}};
    For types try
    my @col_types = @{$sth->{TYPE}};
      thanks a lot Arunbear!

      types works, but it gives me numbers only, I read DBI docs, and I found:
      my @names = map { scalar $dbh->type_info($_)->{TYPE_NAME} } @{ $sth->{ +TYPE} };
      which works perfectly. Thanks anyway for pointing me.