t-sql 2012 using temp table

  • In some new t-sql 2012 that I am going to be setting up, I will be loading some data into #temp tables. I will be then joining the #temp tables to the main query that I will be executing. There will be times when one or two of the #temp tables may not have any data in them. Thus I am not certain how to handle this situtation. Would I just join to the main query with a left join? Would I need some if then else logic?

    Thus would you show me some t-sql 2012 that would solve my problem for me?

  • When using Temporary tables, you treat them just like any other table. For the duration of that session, and that session's point of view, they are "real" tables. If you need to JOIN to them, you would do so like any other table; if that means using a LEFT/RIGHT join or APPLY, then that's what you need to do.

    I don't really understand what you mean by how T-SQL 2012 would solve your problem. What version of SQL Server were you using before? I wouldn't really say that Temporary Tables have changed that much from 2008 to 2012, but it's been a long time since I looked at the feature list.

    All in all, your question is quite vague, so I don't really know what you really want as an answer. If you could provide some examples and data to show what your needs and goals are, that would be much better. It may even be that you don't need to use a Temporary Table. You might, for example, be better off using a CTE or creating a VIEW.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • wendy elizabeth - Monday, October 2, 2017 2:34 PM

    In some new t-sql 2012 that I am going to be setting up, I will be loading some data into #temp tables. I will be then joining the #temp tables to the main query that I will be executing. There will be times when one or two of the #temp tables may not have any data in them. Thus I am not certain how to handle this situtation. Would I just join to the main query with a left join? Would I need some if then else logic?

    Thus would you show me some t-sql 2012 that would solve my problem for me?

    What do you mean by statement - "Some of the #temp tables will not have data in them" ? SQL Server handles the #temp table as other tables. Please provide the details.
    Thanks 🙂

    First solve the problem then write the code !

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

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