NopCommerce Category By ProductId →Many To Many Relation
ALTER function [dbo].[GeyCategoryByProductIdQuery]
(
@productId int
)
RETURNS varchar(400)
AS
BEGIN
DECLARE @categoriId int
Select TOP(1) @categoriId = CategoryId from Product_Category_Mapping with (NOLOCK) where ProductId=@productId
declare @SubcategoryName nvarchar(400)
select top(1) @SubcategoryName=Name from Category where Id=@categoriId
declare @parentCategoryId int
select top(1) @parentCategoryId=ParentCategoryId from Category where Id= @categoriId
declare @categoryName nvarchar(400)
select top(1) @categoryName = Name from Category where Id= @parentCategoryId
return concat(@categoryName,’-’,@SubcategoryName)
END