I am not familiar with the syntax to make this UDF work. I have verified that the select statements work just fine. What am I doing wrong? Thanks for your help.
CREATE FUNCTION [dbo].[getContentURL]
(
@Tier int, -- this is the ID of the location
@Tier_ID int -- this is what level the article is attached
)
RETURNS TABLE
AS
RETURN
(
-- Add the SELECT statement with parameter references here
BEGIN
IF @Tier_ID = 3
select (select '/global/index.cfm/L1-'+cast(B.T1IDFK as varchar(10))+ '/L2-'+cast(A.T2IDFK as varchar(10))+'/L3-'+cast(A.T3ID as varchar(10))+'/') AS URL
from dbo.Tier3 A, dbo.Tier2 B
WHERE A.T3ID = @Tier
AND A.T2IDFK = B.T2ID
END
IF @Tier_ID = 2
BEGIN
select (select '/global/index.cfm/L1-'+cast(A.T1IDFK as varchar(10))+ '/L2-'+cast(A.T2ID as varchar(10))+'/') AS URL
from dbo.Tier2 A
where A.T2ID = @Tier
END
IF @Tier_ID = 1
select A.T1ID, (select '/global/index.cfm/L1-'+cast(A.T1ID as varchar(10))+'/') AS URL
from dbo.Tier1 A
where A.T1ID = @Tier
END
)
GO
CREATE FUNCTION [dbo].[getContentURL]
(
@Tier int, -- this is the ID of the location
@Tier_ID int -- this is what level the article is attached
)
RETURNS TABLE
AS
RETURN
(
-- Add the SELECT statement with parameter references here
BEGIN
IF @Tier_ID = 3
select (select '/global/index.cfm/L1-'+cast(B.T1IDFK as varchar(10))+ '/L2-'+cast(A.T2IDFK as varchar(10))+'/L3-'+cast(A.T3ID as varchar(10))+'/') AS URL
from dbo.Tier3 A, dbo.Tier2 B
WHERE A.T3ID = @Tier
AND A.T2IDFK = B.T2ID
END
IF @Tier_ID = 2
BEGIN
select (select '/global/index.cfm/L1-'+cast(A.T1IDFK as varchar(10))+ '/L2-'+cast(A.T2ID as varchar(10))+'/') AS URL
from dbo.Tier2 A
where A.T2ID = @Tier
END
IF @Tier_ID = 1
select A.T1ID, (select '/global/index.cfm/L1-'+cast(A.T1ID as varchar(10))+'/') AS URL
from dbo.Tier1 A
where A.T1ID = @Tier
END
)
GO