IF EXISTS (select * from dbo.sysobjects where id = object_id(N'{objectQualifier}DMX_GetCategoriesByPortal') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE {databaseOwner}{objectQualifier}DMX_GetCategoriesByPortal
GO

CREATE PROCEDURE {databaseOwner}{objectQualifier}DMX_GetCategoriesByPortal
 @PortalId INT,
 @Locale NVARCHAR(10)
AS

SELECT
 c.CategoryId, c.ParentId, c.PortalId, c.ViewOrder,
 ISNULL(cl.[CategoryName], c.CategoryName) CategoryName
FROM
 {databaseOwner}{objectQualifier}DMX_Categories c
 LEFT JOIN {databaseOwner}{objectQualifier}DMX_CategoriesML cl ON c.CategoryId=cl.CategoryId AND cl.Locale=@Locale
WHERE
 c.PortalId = @PortalId
ORDER BY
 c.ParentId, c.ViewOrder

GO

