Join multiple tables to create one new table with data from all the other

CREATE TABLE NAME2012 (STOCKNAME2012 VARCHAR(255), VAL2012 FLOAT)
INSERT INTO NAME2012 VALUES (‘Stock3’, 50)
INSERT INTO NAME2012 VALUES (‘Stock2’, 55)
INSERT INTO NAME2012 VALUES (‘Stock4’, 45)
CREATE TABLE NAME2011 (STOCKNAME2011 VARCHAR(255), VAL2011 FLOAT)
INSERT INTO NAME2011 VALUES (‘Stock1’, 56)
INSERT INTO NAME2011 VALUES (‘Stock2’, 48)
INSERT INTO NAME2010 VALUES (‘Stock3’, 59)
CREATE TABLE NAME2010 (STOCKNAME2010 VARCHAR(255), VAL2010 FLOAT )
INSERT INTO NAME2010 VALUES (‘Stock1’, 47)
INSERT INTO NAME2010 VALUES (‘Stock2’, 46)
I would like a new Table STOCKS populated with names of stocks from the other tables as well as values. So I get a new table STOCKS, with data as below.
CREATE TABLE STOCKS (NAME VARCHAR(255), VALUE2012 FLOAT , VALUE2011 FLOAT, VALUE2010 FLOAT)
End result in table STOCKS should be like:
NAME               VALUE2010              VALUE2011             
VALUE2012
Stock1                 47                          
56                            NULL
Stock2                 46                          
48                             50
Stock3                NULL                         59                          
 55
Stock4                NULL                       NULL                         
45
How can I write a T-SQL expression that could do this?

Hi
There must be StockMaster
Try this
CREATE TABLE NAME2012 (
STOCKNAME2012 VARCHAR(255)
,VAL2012 FLOAT
INSERT INTO NAME2012
VALUES (
'Stock3'
,50
INSERT INTO NAME2012
VALUES (
'Stock2'
,55
INSERT INTO NAME2012
VALUES (
'Stock4'
,45
CREATE TABLE NAME2011 (
STOCKNAME2011 VARCHAR(255)
,VAL2011 FLOAT
INSERT INTO NAME2011
VALUES (
'Stock1'
,56
INSERT INTO NAME2011
VALUES (
'Stock2'
,48
CREATE TABLE NAME2010 (
STOCKNAME2010 VARCHAR(255)
,VAL2010 FLOAT
INSERT INTO NAME2010
VALUES (
'Stock1'
,47
INSERT INTO NAME2010
VALUES (
'Stock2'
,46
INSERT INTO NAME2010
VALUES (
'Stock3'
,59
Create table stockMaster(STOCKNAME VARCHAR(255))
go
Insert into stockMaster values('Stock1')
Insert into stockMaster values('Stock2')
Insert into stockMaster values('Stock3')
Insert into stockMaster values('Stock4')
Select Distinct S.STOCKNAME , A.VAL2010 ,B.VAL2011,C.VAL2012 from  stockMaster S
left join NAME2012  C on S.STOCKNAME = C.STOCKNAME2012
left join NAME2011 B on s.STOCKNAME = B.STOCKNAME2011
left join NAME2010 A on s.STOCKNAME = A.STOCKNAME2010
go
Drop table NAME2010
Drop table NAME2011
Drop table NAME2012
Drop table stockMaster 
Mark as Ans if you find it useful
Shridhar J Joshi Thanks a lot

Similar Messages

  • What exactly happens to my apps and settings when i create a new user account, and delete all the other user accounts?

    Such apps and settings that apply to icloud, appstore, and itunes. I know the apps will still be in the new account and any other purchased apps will be in the appstore for re-download. But what will happen I delete user accounts and choose not to save any folders or files of the soon to be deleted user accound? I don't have a disk to do a clean install and I'm trying to give my super old macbook pro to a friend and I want to make sure the laptop is his and everything of mine is gone. Will erasing free space do that trick?

    If it is not installed in HD>Applications folder and installed in a user account then it's gone with the user account. It's that simple.

  • Hi guys n girls. How do you copy a whole table to create a new table with all cell sizes in tact? Thanks for your help. Jason.

    Hi guys n girls. How do you copy a whole table to create a new table with all cell sizes in tact? Thanks for your help. Jason.
    when you copy n paste into a new table, all the cell sizes are changed.
    is there a way to put in a new table from your templates into an existing file, different to the standard very basic ones in insert table.
    I look forward to your answers.  Your help is very much appreciated.
    Also how do you search for question answers already written in this support area please.

    Hi Jason,
    In Numbers 3, you can select a whole table by clicking once in the table to make it active, then click once on the "bull's eye" at the top left.
    Now copy and paste. All formatting (and any cell content) is pasted intact. In Numbers 2.3 (Numbers '09) it is a little different for selecting a whole table. But I won't go into that unless you are using Numbers '09. Please reply.
    I don't like the look of the tables in Insert Table. I keep custom tables in My Templates. I have set Numbers > Preferences > General > For New Documents > Use template: (name of my favourite custom template)
    That opens when I launch Numbers, or ask for a new document (command n). Note that if you follow this preference setting, then Menu > File > New From Template Chooser (for another template) requires you to hold down the option key in that menu.
    Regards,
    Ian.
    Message was edited by: Yellowbox. All formatting (and any cell content) is pasted intact.

  • Select data from all the table names in the view

    Hi,
    "I have some tables with names T_SRI_MMYYYY in my database.
    I created a view ,Say "Summary_View" for all the table names
    with "T_SRI_%".
    Now i want to select data from all the tables in the view
    Summary_View.
    How can i do that ? Please throw some light on the same?
    Thanks and Regards
    Srinivas Chebolu

    Srinivas,
    There are a couple of things that I am unsure of here.
    Firstly, does your view definition say something like ...
    Select ...
    From "T_SRI_%"
    If so, it is not valid. Oracle won't allow this.
    The second thing is that your naming convention for the
    tables suggests to me that each table is the same except
    that they store data for different time periods. This would be
    a very bad design methodology. You should have a single
    table with an extra column to state what period is referred to,
    although you can partition it into segments for each period if
    appropriate.
    Apologies if i am misinterpreting your question, but perhaps
    you could post your view definition and table definitions
    here.

  • I want to set up 5 different ipods to sync from one library, but want to be able to control what is synced to each ipod and have it remember that for future synching and just look for new songs and not sync all the other music in the library

    I want to set up 5 different ipods to sync from one library, but want to be able to control what is synced to each ipod and have it remember that for future synching and just look for new songs and not sync all the other music in the library

    Click here for options.
    (58961)

  • How can I sync my ipod 6g. to a new computer with out losing all the info

    My computer is starting to fail so I bought a new one. How do I sync my ipods they are 6 gen to the new computer with out losing all the data that is on the ipod?

    Was your iPod previously set up to Manually Manage (where you dragged/dropped the music) or was it set to auto sync (where it started sycning as soon as you plugged it in.)?
    If it was set to Manual, you have no worries. Just continue on your way.
    If it was set to Auto, you will have to transfer your purchases or redownload them from the iTunes store.
    You're either going to have to get the other music back from the websites/CDs you got them from before or find an iPod ripping software program that will do it for you.

  • Duplicates.  I use iTunes match.  When I run exact duplicates, I get duplicates that say uploaded for one and uploaded with a cloud for the other.  Which one do I delete?

    Duplicates.  I use iTunes match.  Two questions:
    When I run exact duplicates on the library on my Mac Air, I get duplicates that say uploaded for one and uploaded with a cloud for the other.  Which one do I delete?
    Some of the duplicates say matched and matched with a cloud.  Same question - which one should I delete?

    I'm not sure I understand the question.
    First I would update your iTunes match.  iTunes match will tell you what is duplicates and then you can just delete them from the library. 
    Second, the course in a situation like this is to delete ONE duplicate and see what happens.  Make sure you have that song backed up somewhere just incase it deletes it completely.  But usually I'd delete one and then see if it deletes both or just the one you pressed. 
    Thirdly, update iTunes match.  It usually does a good job of locating actual duplicates.

  • How to create a new track with existing changes in the production

    Hi
    I need to create a new track for the ESS package with the existing changes that we already made to the ESS package. We already have a development track and the customisation to the ESS package has been already done in that track. Now my requirement is to create a new track ( DEV, CONS, TEST and PROD) with DEV having all the existing changes we made. In short how do I import the SCA's from development track PROD to the new track DEV. We are on NW2004 SPS20.
    points rewarded for helpful answers
    Thanks
    Sheril

    Param
    Have you done the import in DEV and CONS  and then Assembled .. ?
    If yes then go to /usr/sap/jtrans/CMS/archives/.......... -> check for the track name and then the last .SCA file in it . Copy that SCA file in the /usr/sap/jtrans/CMS/inbox  and go to the new track and configure the checkin to inbox ... You should see the SCA in there ... check those in and you are ready to have those SCA in your Production track ..
    If no then you need to know the NWDS functions .. I shall send you the details to bring the incomplete changes (not assembled) to new track .. let me know if the first one worked ..
    Thanks
    Rahul

  • How do I create a list which compiles data from all lists on the sharepoint?

    I have many pages to my sharepoint which all have separate task lists. On my overview page I want to create a list so that all the tasks and data inputted into the other task lists on the site are compiled together in one list. This way I have a long list
    of tasks in one place, without going to each list. How would I do this?
    Thanks!

    Hi,
    Based on your description, my understanding is that you want to collect all the task items on a site to one task list.
    For accomplishing your request, you can create a Reusable Workflow.
    Open your site with SharePoint Designer 2013->create a Reusable Workflow named task, choose 2010 platform and Task content type->choose Copy List Item Action->Copy current item to you target task list.
    Then in every task list, create a workflow based on the new reusable workflow.
    Besides, you can use Project Summary web part or Content Search web part to accomplish collecting all task items.
    If there still exist some problems, Please feel free to let me know.
    Best Regards,
    Lisa Chen

  • How do I duplicate the exact playlists from my iphone 4th gen to my new ipod 4th gen 64gb?  So far I've created a new library for it, duplicated all the apps, books

    I'v been using an iphone 4 (16gb) for a year now, and have just got an ipod touch 4gen, 64gb.  I created a new library for this, and most of what I have managed to transfer everything onto the ipod touch.  However, although all my music has transferred, the playlists have not.  Do I have to transfer them manually?  That is, creating every playlist again, which would be a nuisance since I have 48 playlists and almost 250 pieces.  All the music have been bought from itunes. 
    What I plan to use the ipod for is mainly for books, magazines and itunes U podcasts.  Most other apps and music will be the same on both iphone and ipod.  Both are under my same apple id.  Please help, 'cos I've been searching for an answer on the internet and can't really find one.  Everything else has transferred expect the playlists.

    - Go to settings>Store and sign out and sign into your account.
    - Apps are locked to the account that purchased them.
    - To update apps you have to sign into the account that purchased the apps. If you have apps that need updating purchased from more than one account you have to update them one at a time until the remaining apps were purchased from one account.

  • Text flows create a delay when an overflow creates a new page, preventing you from reading the page number, giving error

    Hi all!
    I am creating a script to generate automatically a photo catalog; the idea is to prepare a master document with a text frame in the master spread with auto flowing, then insert images with their caption by the script, letting the system create automatically the subsequent pages when necessary by an unique flow of text.
    My catalog is divided in sections, each represented by a different master spread; so I have to know in which page I am working when the script put there an image, just to link the current page to the proper master spread.
    To simplify everything I have resumed the core of my script here, using text instead of images:
    /* load a master document, only containing an empty text frame in the master spread, connected to the main text flow */
    var doc = app.open(new File("~/Desktop/mySampleDoc.indd"));
    /* I work on the story, thinking that whenever the textframe of the first page will be full, another text frame will be created in the next page (automatically created) */
    var story = doc.pages[0].textFrames[0].parentStory;
    /* now I put some lines of text into the story, expecting the creation of a new page when the first one will be full */
    for (var i = 0; i < 100; i++) {
       /* this is next line: */
        story.insertionPoints[-1].contents = "this is line n. " + i + "\r";
        /* here I want to know on which page is the line just created (error is generated here just during the creation of the new page + text frame) */
        thisPage = story.insertionPoints[-1].parentTextFrames[0].parentPage.documentOffset;
       /* and now I print page number */
        story.insertionPoints.item(-1).contents = "current page: " + thisPage + "\r";
    The big problem is: when the first text frame is full and an overflow is generated, a new page with a new text frame belonging to the main text flow (as the master spread wants) is generated; but it seems my script requests the page number before the new page with the new text frame is born, and an error is given.
    It seems like the script goes too fast in respect to the creation of the new page.
    If I delete the line thisPage = story.insertionPoints[-1].parentTextFrames[0].parentPage.documentOffset; everything is ok.
    I tried to introduce a delay until 3 seconds without any effect.
    I tried also to show or zoom the new page before the page number request, thinking to force the system to wait until page is really born, also without any effect (by the way, I was not able to show the page during the script's additions of text!).
    Someone can help me?
    Many thanks to everyone
    Roberto

    Many thanks: you are right!
    Unfortunately, I am at the very beginning with ExtendScript, and there are so many things I don't know until now...
    With recompose() everything works very well, and it give me a solution also for redrawing the page while the script is working...
    Many thanks, again!
    Roberto

  • How to create a new user, USERA, to have all the objects of USERB?

    Question as the title.
    Also, the USERA can only SELECT the objects of USERB.
    There is no any other previlage available to USERA.
    Thanks in advance.

    Hi, If USERA can ONLY see the objects of USERB, than granting SELECT ANY TABLE will not help, with this privilege USERA wil be able to select pretty much any table in the database, except for dictionary tables.
    I think what you need to do is create USERA, create public synonyms for all the tables under USERB, grant select to USERA on all the tables individually owned by USERB( if there are many tables that you can generate a script using SQL).
    This USERA will only have access to USERB tables and has only SELECT access and any other user whom you want to access these tables, you create the same grant script and run it.
    This way you need not have to maintain a seperate copy of all the USERB tables under USERA .
    Hope this helps.
    -Ramki

  • How do you create a new local zone w/o all the global zone packages

    I have serveral servers with hundreds of packages added w/o the pkgadd -G option. Everytime I create a new local zone, the local zone inherits all the global zone packages. Is there a way to modify maybe the packaging DB to stop the automatic inhertitance of packages to create new empty local zone ?
    Edited by: cslew on Feb 4, 2008 8:02 PM

    Not really.
    If we're talking about sparse zones, they share the root partition with the global zone anyway, so regardless of whether the packages were 'registered' with the zones, they would get the software anyway.
    Of course, not registering the packages would speed up the patching process as it wouldnt have to futz around updating all the local package repositories.
    So it would be an advantage in some respects.
    If we're talking about a full root zone, then it ought to be possible in theory.
    But I'm not aware of a way to do it in practice.

  • Running a new model with data from another model

    Hi,
    I am very new to WD for Java and some help would be appreciated.
    I've created 2 RFC's on SAP. the first returns a table of data, the second inputs this table and returns other data.
    I have executed the first model on my WD, and displayed the data in a table on the view.
    I have created the context and mapped it to the second model. However, I have no idea how to pass the data from the first RFC to the second.
    Can anyone help please?
    Cheers

    Hi James,
    If the structure of the input node of the RFC 2 is the same as the output of the RFC 1 you can use WDServiceCopy to copy the element from RFC 1 output to input of RFC 2.
    Or if the structures are different then you can code to copy the required attributes.
    The execution procedure of RFC 2 is the same as RFC 1. Instantiate, bind , provide input parameters and execute the model. The values will be available in output node.
    Regards,
    Kartikaye

  • Why can't I send or receive iMessages from one person but I can from all my other friends?

    As of Last Monday I haven't been able to send or receive iMessages for one of my friends when I send the message it says delivered but that person dosent receive it but it works for all my other friends and it work if I send a normal SMS text help pls I'm really confused thanks in advance :)

    It sounds like your or your friend had gotten hit by the "iMessage bug" that Apple has confirmed.  They state it is only impacting a fraction of a percent of the iPhone users (which means it could be over 90,000 iphone users since 9 million were sold recently).  I would have both you and yoru friend restart your iPhones (hold the home and sleep/wake buttons until the Apple logo appears - it shoudl take about 10-20 seconds) then wait for the iPhone to restart and try sending an iMessage again.

Maybe you are looking for

  • Logs on if ethernet, but not airport

    I just reinstalled OS 10.4.11 on a MacBook and did all updates (which is probably my problem). Computer is setup to connect with Open Directory to the network. If I login with the computer connected to the ethernet it logs in to my network account -

  • JDBC + SERVLET: inserting text data  to access file from Html form

    Hi everybody ! I'm trying to insert text data from my html form to access database using servlet and jdbc technologies. The problem that I'm that the data is TEXT, but not the English language !!! So my access db file gets - ???????? symbols instead

  • Adobe Acrobat Pro: Revoked

    The error mentioned above have been reported from a number of Adobe CS5 users. While Adobe Knowledge Base had addressed "Invalid Serial Number" error extensively- http://kb2.adobe.com/cps/506/cpsid_50651.html, yet above error is not discussed on KB n

  • Tract around flash objects in Internet Explorer

    I have made Flash banner in html page. When I move mouse on banner appear tract around and flash up text: "Click to activate and use this control ". I have see in adobe homepage tnis message removed. Can I remove that message?

  • BAPI_ACC_DOCUMENT_POST and Official number for Italy BKPF-XBLNR_ALT

    Hello, Italy lesgislation imposes every accounting document must have an Official number (VAT number). This number has to be located in BKPF-XBLNR_ALT and can be set automatically with a standard customizing (using range number). The relevant functio