Temp Table in View

  • Hi,

    I want to use two select queries in one view. The scenario is like, I will use result of one query as a join on another query. I can do this fine with temp tables.

    But I want to achieve same stuff in View and it seems like view dont allow temp table.. Does anyone knows better way for this?

    :rolleyes:

  • Subqueries, CTEs, or inline TVFs. Views need to be a single statement. Also remember views aren't encapsulated result sets unless you turn them into indexed views. Any time you call the view, you have to rerun the entire execution plan.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • Views do not allow temp tables, but you can still use a derived table in the JOIN. Can you provide an example of what you are trying to do?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • As John mentioned, more information and preferably code, would help.

    I would learn towards a CTE if you have temp tables you are trying to use.

Viewing 4 posts - 1 through 3 (of 3 total)

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