我有以下 SQL 函数
ALTER FUNCTION FunctionTEST (@itemID bigint) RETURNS table AS RETURN
(
(SELECT top 1 Pic_Path from PictureDetails WHERE PictureDetails.Item_ID = @itemID)
)
如果根据指定的参数找到,此函数将返回第一行。如果没有针对参数找到记录,我希望此函数返回空行。我认为这应该是一个简单的任务,但我不熟悉 SQL 函数。下面是我用来调用函数的实际查询。
SELECT
NewClientTB.FirstName, NewClientTB.LastName, NewClientTB.EMail, NewClientTB.ContactNo,
ADDetails.AD_ID, ADDetails.AD_EXactAddress,
ADDetails.AD_PostingTime, ADDetails.AD_Description, ADDetails.AD_Title,
ItemDetails.Item_ID, ItemDetails.Item_Price,
Regions.R_Description,
Cities.C_Name,
GCategories.GC_Description,
SCategories.SC_Description,
PictureDetails.Pic_Path
FROM NewClientTB, ADDetails,ItemDetails, Regions, Cities, GCategories,
SCategories, PictureDetails
WHERE FREETEXT (ADDetails.AD_Title, 'selling')
AND FREETEXT (ADDetails.AD_Description, 'selling')
AND ADDetails.AD_PosterID = NewClientTB.UserID
AND ADDetails.AD_ID = ItemDetails.AD_ID
AND Regions.R_ID = ADDetails.AD_Region
AND Cities.R_ID = ADDetails.AD_Region AND Cities.C_ID = ADDetails.AD_City
AND ItemDetails.Item_GCategory = GCategories.GC_ID
AND ItemDetails.Item_SCategory = SCategories.SC_ID AND ItemDetails.Item_GCategory =
SCategories.GC_ID
AND PictureDetails.Pic_Path = (select * from dbo.FunctionTEST(ADDetails.AD_ID))