How to add 2 Temp-table

  • Dear All ,

    How to add 2 Temp-table

    Temp Table 1 :

    select no,name,age insert into #temp1 from emptable

    Temp Table 2 :

    select address,state,county insert into #temp2 from locatetable

    now i want select all the column in one temp-table

    Ex: no,name,age,address,state,county ===>all columns in one table

    How can i do this kindly advise me ........

    Thanks & Regards,

    Hasan

  • you'll have to provide the linking criteri that shows that an address in one table belongs to the employee in the other;

    and you'll simply use a left outer join to get it all in a single statelemt:

    select

    emptable.no,

    emptable.name,

    emptable.age,

    locatetable.address,

    locatetable.state,

    locatetable.county

    from emptable

    --this is what is missing:

    --how are the two tables related? addrID?EmpID?

    LEFT OUTER JOIN locatetable ON emptable.no = locatetable.no

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • i dont have a any same column like id..

    two table column's are fully different...

    Kindly advise me how to add two temp-table columns

  • reliably? you cannot. to join data from two tables, there must be a join criteria of some kind.

    if you have 5 employees in one table, how do you know which address is theirs in another.

    there must be some column the two share.

    if there is not, you have a design problem.

    show us the CREATE TABLE definitions of both tables, so we can really help you.

    if both tables have an identity, maybe you can make an assumption nad use row number to generate the join, since that would need something to order the data by.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • CELKO (10/25/2010)


    The best book for a complete beginner is THE MANGA GUIDE TO DATABASES.

    Awesome book, even for the not-so-beginner.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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