Trying to replace UNION

  • Hey everyone! I'm having a slight problem with the Union Template. When I try previewing the LEARN MORE button so the lightbox appears and the contact us form pops-up, it doesn't show the full rectangle around the form nor does the text fit in the form fields. What can I do to fix this? Thanks so much! VMware Training in Chennai πŸ™‚ | Web Designing Training in Chennai πŸ™‚

  • SQL006 (2/3/2016)


    Thank you guys for your valuable inputs. I checked the execution plan for the UNION and the CROSS APPLY query, i am surprised that the UNION query is still faster than CROSS APPLY query by 1-2 seconds,even though in UNION query it accessing the table twice in comparison to CROSS APPLY where it accessing the table only once.

    For the execution order of query i referred the itzik ben-gan logical order processing.

    Thanks for all your suggestions.

    That's an interesting and unexpected observation. Care to share your code?

    β€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • It might be caused by how the date ranges are handled. The union might allow to get a more straight forward plan.

    Maybe if you combine the solutions, you could get better performance.

    SELECT

    t.Id,

    x.Amount,

    t.CashFlowDate,

    x.AmtType

    FROM #Test t

    CROSS APPLY (

    VALUES

    (t.Principal, 'Principal'), --No need for additional date condition

    (CASE WHEN t.CashFlowDate >= '2016-01-02' THEN t.Interest END, 'Interest') --Exclude the first day

    ) x (Amount,AmtType)

    WHERE x.Amount > 0

    AND CashFlowDate between '2016-01-01' AND '2016-01-05'; --Leave a single date condition

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 3 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic. Login to reply