• oliver.morris (3/7/2013)


    Hi Dwain,

    Thanks for the help, I made a few changes but the key is that I need to push the column_id variable to each function. How do I do this? With the cursor I set column_id is the cursor which it iterates through.

    SELECT *

    FROM [dbo].[TSC_ExportedColumnIds] a

    CROSS APPLY [dbo].[udf_TSC_qry_ExportBlockColumnParam1](a.ID) b

    WHERE a.ColumnType IN (1,2)

    UNION ALL

    SELECT *

    FROM [dbo].[TSC_ExportedColumnIds] a

    CROSS APPLY [dbo].[udf_TSC_qry_ExportBlockColumnParam2](a.ID,4) b

    WHERE a.ColumnType IN (1,2)

    UNION ALL

    SELECT A,B,C,D,E,F,G

    FROM [dbo].[TSC_ExportedColumnIds] a

    CROSS APPLY [dbo].[udf_TSC_qry_ExportEventColumnParam0](a.ID,4) b

    WHERE a.ColumnType = 3;

    Sorry, I never really read the whole thread, so pretty sure that my post above is incorrect. Instead, give this a shot: -

    SELECT A,B,C,D,E,F,G

    FROM (SELECT A.ID, B.ColumnType

    FROM dbo.TSC_ExportedColumnIds A

    INNER JOIN TSC_COLUMNS B ON A.ID = B.ID

    ) a

    CROSS APPLY [dbo].[udf_TSC_qry_ExportBlockColumnParam1](a.ID) b

    WHERE a.ColumnType IN (1,2)

    UNION ALL

    SELECT A,B,C,D,E,F,G

    FROM (SELECT A.ID, B.ColumnType

    FROM dbo.TSC_ExportedColumnIds A

    INNER JOIN TSC_COLUMNS B ON A.ID = B.ID

    ) a

    CROSS APPLY [dbo].[udf_TSC_qry_ExportBlockColumnParam2](a.ID,4) b

    WHERE a.ColumnType IN (1,2)

    UNION ALL

    SELECT A,B,C,D,E,F,G

    FROM (SELECT A.ID, B.ColumnType

    FROM dbo.TSC_ExportedColumnIds A

    INNER JOIN TSC_COLUMNS B ON A.ID = B.ID

    ) a

    CROSS APPLY [dbo].[udf_TSC_qry_ExportBlockColumnParam0](a.ID,4) b

    WHERE a.ColumnType = 3;


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/