• I have managed a workaround, it is a bit longwinded but it seems to work as I have covered every scenario I think.

    USE [TestData]

    GO

    /****** Object: StoredProcedure [dbo].[droptable] Script Date: 07/10/2013 14:11:37 ******/

    SET ANSI_NULLS ON

    GO

    Alter procedure [dbo].[checkcolumnsexists]

    AS

    BEGIN

    /* They all exist so exec the full cleanse procedures */

    if dbo.ColumnExists('SOFTWARE_MANUFACTURER') = 'Y'

    and dbo.ColumnExists('PRODUCT_NAME') = 'Y'

    and dbo.ColumnExists('PRODUCT_VERSION') = 'Y'

    BEGIN

    Exec cleanseDATA;

    END

    else if

    /* If the software manufacturer and product name exists so exec both procedures */

    dbo.ColumnExists('SOFTWARE_MANUFACTURER') = 'Y'

    and dbo.ColumnExists('PRODUCT_NAME') = 'Y'

    BEGIN

    -- exec softwaremancleanse;

    -- exec productnamecleanse;

    END

    else if

    /* If the software manufacturer and product version exists so exec both procedures */

    dbo.ColumnExists('SOFTWARE_MANUFACTURER') = 'Y'

    and dbo.ColumnExists('PRODUCT_VERSION') = 'Y'

    BEGIN

    -- exec softwaremancleanse;

    -- exec productversioncleanse;

    END

    else if

    /* If the product name and version exists so exec both procedures */

    dbo.ColumnExists('PRODUCT_NAME') = 'Y'

    and dbo.ColumnExists('PRODUCT_VERSION') = 'Y'

    BEGIN

    -- exec productnamecleanse;

    -- exec productversioncleanse;

    END

    else if

    /* Only the software manufacturer exists so execute cleanse Software manufacturer procedure */

    dbo.ColumnExists('SOFTWARE_MANUFACTURER') = 'Y'

    and dbo.ColumnExists('PRODUCT_NAME') = 'N'

    and dbo.ColumnExists('PRODUCT_VERSION') = 'N'

    BEGIN

    -- exec softwaremancleanse;

    END

    else if

    /* Only the product name exists so execute cleanse product name procedure */

    dbo.ColumnExists('SOFTWARE_MANUFACTURER') = 'N'

    and dbo.ColumnExists('PRODUCT_NAME') = 'Y'

    and dbo.ColumnExists('PRODUCT_VERSION') = 'N'

    BEGIN

    -- exec productnamecleanse;

    END

    else if

    /* Only the product version exists so execute cleanse version procedure */

    dbo.ColumnExists('SOFTWARE_MANUFACTURER') = 'N'

    and dbo.ColumnExists('PRODUCT_NAME') = 'N'

    and dbo.ColumnExists('PRODUCT_VERSION') = 'Y'

    BEGIN

    -- exec productversioncleanse;

    END

    END