Hi i am a newbie to SQL and creating a a proc in SQL 2000 where i wished to link data from two tables i want to retrieve both a default section to link from tblcategories and a non-default (multiple) section from tblcategories. I have decided the easiest and most flexable way to this would be to use a binary maskid. I have createed two stored procs to do this could you advise me as to which is the most efficient method is there a more efficient way of doing this (i want to stick with the bitwise mask if possible)
Method 1:
Method 2:
thanks
-Gus
Method 1:
Code:
CREATE PROCEDURE [dbo].[usp_CategorySectionExist]
@CategoryID int,
@SiteID int, --identifies which site section displayed on
@SectionID int, -- identifies default section
@SectionMask int -- identifies non-default section
AS
SELECT --checks exists for default section
[C].Section_ID,
[C].Section_Mask,
[S].SectionName
FROM
tblCategories AS [C]
JOIN
tblSections AS [S]
ON
[C].Section_ID = [S].SectionID
WHERE
[C].Category_ID = @CategoryID -- check current category
AND
[S].SectionID = @SectionID -- check default category exist
AND
([S].SiteMask & @SiteID > 0) -- check if exists on current site
UNION
SELECT --check exists for non-default
C.Section_ID,
C.Section_Mask,
S.SectionName
FROM
tblCategories AS [C]
JOIN
tblSections AS [S]
ON
(C.Section_Mask & S.SectionMaskID) > 0
WHERE
(C.Category_ID = @CategoryID)
AND
(S.SectionMaskID & @SectionMask > 0)
AND
(S.SiteMask & @SiteID > 0)
Method 2:
Code:
CREATE PROCEDURE [dbo].[usp_CategorySectionExist1]
@CategoryID int,
@SiteID int, --identifies which site section displayed on
@SectionID int, -- identifies default section
@SectionMask int -- identifies non-default section
AS
DECLARE
@CatSectionID int,
@CatSectionMask int
SELECT @CatSectionID = [Section_ID], @CatSectionMask = [Section_Mask] FROM [tblCategories] WHERE [Category_ID] = @CategoryID
SELECT
[S].SectionName --checks exists for default section
FROM
tblSections AS [S]
WHERE
[S].SectionID = @SectionID -- session section id
AND
[S].SectionID = @CatSectionID -- current category section id
AND
[S].SiteMask = @SiteID
UNION
SELECT
[S].SectionName --check exists for non-default
FROM
tblSections AS [S]
WHERE
([S].SectionMaskID & @CatSectionMask) > 0 -- current category mask id
AND
([S].SectionMaskID & @SectionMask > 0) -- session section maskid
AND
(S.SiteMask & @SiteID > 0)
-Gus