-- =============================================
-- Author:      Gartle LLC
-- Release:     10.0, 2022-07-05
-- Description: The view selects value for the @category_id parameter
-- =============================================

CREATE VIEW [s20].[xl_list_category_id]
AS

SELECT
    c.id
    , c.name
FROM
    s20.categories c
    INNER JOIN s20.category_users cp ON cp.category_id = c.id
    INNER JOIN s20.users u ON
        u.id = cp.user_id
        AND u.username = USER_NAME()
WHERE
    cp.permission IN (1, 2)