Forum Replies Created

Viewing 15 posts - 1,111 through 1,125 (of 2,645 total)

  • Reply To: Recursive CTE vs UNION ALL in a VIEW

    Mauricio_ wrote:

    So, from your point of view, in this case it's better to use UNION ALL even when some levels are not used than to use a recursive CTE?. I...

  • Reply To: Recursive CTE vs UNION ALL in a VIEW

    Mauricio_ wrote:

    No, I think that's because I had some problems executing the script for exporting data (it was too huge). In my databases both views produce the same result.

    Well, there's...

  • Reply To: Recursive CTE vs UNION ALL in a VIEW

    I also think they are logically different queries and produce different results. I ran the original query and it returned over 400k rows (in over 20 minutes). The rCTE version...

  • Reply To: Recursive CTE vs UNION ALL in a VIEW

    I added these indexes:

    CREATE NONCLUSTERED INDEX [IX_DBRVARE_NR_INC_NAVN_TYPE]
    ON [dbo].[DBRVARE] ([NR])
    INCLUDE ([NAVN],[TYPE])
    CREATE VIEW [dbo].[vwDBDOPSKSumant]
    WITH SCHEMABINDING AS
    SELECT DOP.NR,
    SUM(ISNULL(DOP.ANT,0)) SUMANT
    ...
  • Reply To: Recursive CTE vs UNION ALL in a VIEW

    I think the indexed view I suggested on dbo.DBDOPSK will reduce the reads on that that table.

    For dbo.DBRVARE, I would try adding an index on column (NR) and INCLUDE (all...

  • Reply To: Recursive CTE vs UNION ALL in a VIEW

    Mauricio_ wrote:

    That's an interesting alternative. Right now, as I said before, CTE view performs better if you filter for one of the first 2 columns. However, if you just SELECT...

  • Reply To: Recursive CTE vs UNION ALL in a VIEW

    Mauricio_ wrote:

    I will try them and let you know. I like more the TVF than the function in this case. Right now, view is working fine but I'm facing a...

  • Reply To: Recursive CTE vs UNION ALL in a VIEW

    Another option would be to create a view or user-defined function or table-valued function. I'm not sure if this would be any more efficient without you testing.

    User defined function:

                

    February 17, 2020 at 2:04 pm

    #3726429

  • Reply To: Recursive CTE vs UNION ALL in a VIEW

    Mauricio_ wrote:

    No, this won't work. As I said before, you can't have aggregate functions in the recursive part of a recursive CTE.

    Ok, I see and agree.

    So did your initial query...

  • Reply To: Recursive CTE vs UNION ALL in a VIEW

    CREATE VIEW [dbo].[vRecipe] AS

    WITH RECIPE_DBVARE (OPNR, DOPNR, ANTL, ANT, ANTS, SVIND, RVNR, RVNAVN, TYPE, NIVEAU, PARENT, LINE, PLINE)
    AS
    (
    SELECT VR.NR ...

    • This reply was modified 5 years, 7 months ago by Jonathan AC Roberts. Reason: missed an outer apply
  • Reply To: Recursive CTE vs UNION ALL in a VIEW

    I don't understand why you are getting an overflow error when selecting from the table but not from the CTE?

    Surely they add up to the same value wherever you do...

  • Reply To: Recursive CTE vs UNION ALL in a VIEW

    Why is it that you are not using:

    OUTER APPLY (SELECT SUM(ANT) as SUMANT
    ...
  • Viewing 15 posts - 1,111 through 1,125 (of 2,645 total)