I am writing a function which I hope to use as a column value in a
select query. The function recursively walks a taxonomic heirarchy,
extracting the name for an organism at the taxonomic level requested
by the user. I'm having trouble figuring out the syntax to call the
function from itself (see **1), and the value returned.
When I test the funciton, it says 'commands completed successfully',
but nothing is returned. This is in SQL2000, runing on Windows2000.
The table the function acts on is:
CREATE TABLE [dbo].[tblbenthictaxa] (
[tsn] [int] IDENTITY (1, 1) NOT NULL ,
[rank_id] [int] NOT NULL ,
[dir_parent_tsn] [int] NULL ,
[req_parent_tsn] [int] NOT NULL ,
[taxa_name] [varchar] (50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT
NULL
) ON [PRIMARY]
GO
ReqParentTSN is the recursive link to rows in the table;
Level is the taxonomic level the user requested (an integer
representing Order, Family, Genus or Species).
CREATE FUNCTION dbo.CBN_RecursT axa (
@ReqParentTSN int,
@Level int
)
RETURNS varchar(100) AS
BEGIN
Declare @Rank int,
@taxaname varchar(100)
SELECT @ReqParentTSN = tblbenthictaxa. req_parent_tsn,
@TaxaName = tblbenthictaxa. taxa_name,
@Rank = tblbenthictaxa. rank_id
FROM tblbenthictaxa
WHERE tblbenthictaxa. TSN=@ReqParentT SN
if @Rank > @Level
**1 --exec CBN_RecursTaxa @ReqParentTSN, @Level
RETURN @TaxaName
END
Thanks in advance for any help,
Tim
select query. The function recursively walks a taxonomic heirarchy,
extracting the name for an organism at the taxonomic level requested
by the user. I'm having trouble figuring out the syntax to call the
function from itself (see **1), and the value returned.
When I test the funciton, it says 'commands completed successfully',
but nothing is returned. This is in SQL2000, runing on Windows2000.
The table the function acts on is:
CREATE TABLE [dbo].[tblbenthictaxa] (
[tsn] [int] IDENTITY (1, 1) NOT NULL ,
[rank_id] [int] NOT NULL ,
[dir_parent_tsn] [int] NULL ,
[req_parent_tsn] [int] NOT NULL ,
[taxa_name] [varchar] (50) COLLATE SQL_Latin1_Gene ral_CP1_CI_AS NOT
NULL
) ON [PRIMARY]
GO
ReqParentTSN is the recursive link to rows in the table;
Level is the taxonomic level the user requested (an integer
representing Order, Family, Genus or Species).
CREATE FUNCTION dbo.CBN_RecursT axa (
@ReqParentTSN int,
@Level int
)
RETURNS varchar(100) AS
BEGIN
Declare @Rank int,
@taxaname varchar(100)
SELECT @ReqParentTSN = tblbenthictaxa. req_parent_tsn,
@TaxaName = tblbenthictaxa. taxa_name,
@Rank = tblbenthictaxa. rank_id
FROM tblbenthictaxa
WHERE tblbenthictaxa. TSN=@ReqParentT SN
if @Rank > @Level
**1 --exec CBN_RecursTaxa @ReqParentTSN, @Level
RETURN @TaxaName
END
Thanks in advance for any help,
Tim
Comment