How to add two #Temptables

  • SELECT rf.ContainerNo,rf.BookNo,BC.seal1No,BC.tareweight as tareweight,

    BC.cargoweight as cargoweight,BC.weightunit into #tempops

    FROM operationdetail rf (Nolock)

    INNER JOIN BL (Nolock) ON BL.book_no=rf.BookNo

    INNER JOIN BL_cargo BC(Nolock) ON BC.BL_NO=BL.BL_NO and BC.eqpid=rf.ContainerNo

    WHERE BL.status <>'v' AND rf.reftype='B'

    SELECT rf.ContainerNo,rf.BookNo,BC.seal1No,BC.tareweight as tareweight,

    BC.cargoweight as cargoweight,BC.weightunit into #tempops1

    FROM operationdetail rf (Nolock)

    INNER JOIN combined_master cm (Nolock) ON cm.Bookno=rf.BookNo

    INNER JOIN BL (Nolock) ON BL.bl_no=cm.nominated_bl

    INNER JOIN BL_cargo BC(Nolock) ON BC.BL_NO=BL.BL_NO and BC.eqpid=rf.ContainerNo

    WHERE BL.status <>'v' AND rf.reftype='B'

    I have 2 temptable

    1.#tempops

    2.#tempops1

    i want add( combine) two temp table with out using UNION ,

    1 st temptable have 10 recods,

    2 nd temptable have 20 records,

    i want get 30 records in one temp table ,how to do ,

    can any one advise me please ???

  • s.chandrahasan (10/22/2010)


    SELECT rf.ContainerNo,rf.BookNo,BC.seal1No,BC.tareweight as tareweight,

    BC.cargoweight as cargoweight,BC.weightunit into #tempops

    FROM operationdetail rf (Nolock)

    INNER JOIN BL (Nolock) ON BL.book_no=rf.BookNo

    INNER JOIN BL_cargo BC(Nolock) ON BC.BL_NO=BL.BL_NO and BC.eqpid=rf.ContainerNo

    WHERE BL.status <>'v' AND rf.reftype='B'

    SELECT rf.ContainerNo,rf.BookNo,BC.seal1No,BC.tareweight as tareweight,

    BC.cargoweight as cargoweight,BC.weightunit into #tempops1

    FROM operationdetail rf (Nolock)

    INNER JOIN combined_master cm (Nolock) ON cm.Bookno=rf.BookNo

    INNER JOIN BL (Nolock) ON BL.bl_no=cm.nominated_bl

    INNER JOIN BL_cargo BC(Nolock) ON BC.BL_NO=BL.BL_NO and BC.eqpid=rf.ContainerNo

    WHERE BL.status <>'v' AND rf.reftype='B'

    I have 2 temptable

    1.#tempops

    2.#tempops1

    i want add( combine) two temp table with out using UNION ,

    1 st temptable have 10 recods,

    2 nd temptable have 20 records,

    i want get 30 records in one temp table ,how to do ,

    can any one advise me please ???

    Change the 2nd query to:

    INSERT INTO #tempops

    SELECT rf.ContainerNo,rf.BookNo,BC.seal1No,BC.tareweight as tareweight,

    BC.cargoweight as cargoweight,BC.weightunit FROM operationdetail rf (Nolock)

    INNER JOIN combined_master cm (Nolock) ON cm.Bookno=rf.BookNo

    INNER JOIN BL (Nolock) ON BL.bl_no=cm.nominated_bl

    INNER JOIN BL_cargo BC(Nolock) ON BC.BL_NO=BL.BL_NO and BC.eqpid=rf.ContainerNo

    WHERE BL.status <>'v' AND rf.reftype='B'



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Rather than using SELECT INTO for your second statement, why not just use INSERT INTO?

    Edit: looks like Alvin and I are operating on the same wavelength today! 🙂

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

  • How about

    SELECT your_statement1

    UNION ALL

    SELECT your_statement2

    ?

    Side note: you don't really need to store it in two temp tables before the UNION operation (as long as you don't need those separate tables for any other processing...)



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Ray K (10/22/2010)


    Rather than using SELECT INTO for your second statement, why not just use INSERT INTO?

    Edit: looks like Alvin and I are operating on the same wavelength today! 🙂

    I feel sorry for you Ray if you're operating on the same wavelength as me. 😀



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Alvin Ramard (10/22/2010)


    Ray K (10/22/2010)


    Rather than using SELECT INTO for your second statement, why not just use INSERT INTO?

    Edit: looks like Alvin and I are operating on the same wavelength today! 🙂

    I feel sorry for you Ray if you're operating on the same wavelength as me. 😀

    That's funny . . . my wife says the same thing to me! :hehe:

    +--------------------------------------------------------------------------------------+
    Check out my blog at https://pianorayk.wordpress.com/

  • Dear All,

    Thanks a lot Alvin Ramard.............:-)

Viewing 7 posts - 1 through 6 (of 6 total)

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