• oliver.morris (3/7/2013)


    Thanks for the help this makes sense. The query works considerably faster. However I have one issue. Each part needs to run in order e.g.

    For the 1st ID - if it was type 1 for example it needs to run

    udf_TSC_qry_ExportBlockColumnParam1

    and then

    udf_TSC_qry_ExportBlockColumnParam2

    So that in the output it is organised like:

    OutputParam1 (ID 1)

    OutputParam2 (ID 1)

    OutputParam1 (ID 2)

    OutputParam2 (ID 2)

    and not

    OutputParam1 (ID 1)

    OutputParam1 (ID 2)

    OutputParam2 (ID 1)

    OutputParam2 (ID 2)

    I hope this makes sense. Many thanks for your help, its almost there and runs in 1 second compared to 1 minute!

    Oliver

    SELECT *

    FROM [dbo].[TSC_ExportedColumnIds] a

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

    WHERE a.ColumnType = 1

    UNION ALL

    SELECT *

    FROM [dbo].[TSC_ExportedColumnIds] a

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

    WHERE a.ColumnType = 1

    UNION ALL

    SELECT *

    FROM [dbo].[TSC_ExportedColumnIds] a

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

    WHERE a.ColumnType = 2

    UNION ALL

    SELECT *

    FROM [dbo].[TSC_ExportedColumnIds] a

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

    WHERE a.ColumnType = 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;

    Looks like I was pretty close. Glad you worked it out.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St