How can i get the price by joining StockIn and StockOut inventory (FIFO)

I have 2 example table 
First StockIn table
declare @StockIn table (StockID int ,qty decimal(16,2),Price decimal(16,2), tranDate Date , running int)
insert into @StockIn(StockID , qty ,  Price, tranDate  , running) values
(1 , 5 , 430 , '2014-10-09' , 1),
(1 , 10 , 431 , '2014-12-09' , 2),
(1 , 15 , 432 , '2015-02-02' , 3),
(2 , 8 , 450 , '2014-08-05' , 1),
(2 , 6 , 451 , '2014-10-09' , 2),
(2 , 15 , 452 , '2015-02-02' , 3)
Represent item which go into the stock order by date (running column is , run number in stockID  order by date )
Second StockOut table
declare @StockOut table (StockID int ,qty decimal(16,2), lineid int)
insert into @StockOut(StockID  ,qty , lineid ) values
(1 , 10 , 2),
(1 , 10 , 4),
(2 , 12 , 8),
Represent item which go out the stock . But this table doesn't have price of each item , I want to join this 2 table (join stockID) for getting the price from
@StockIn table  by FIFO  , into @StockOut table  row by row .
I can do this if I dont care about  lineid  but  i need to get the total price (qty * price) of any lineid .
How Can i do this ?
Thanks
This is the  Result i expect 

Thanks Jason
A Long
>>  https://www.simple-talk.com/sql/performance/set-based-speed-phreakery-the-fifo-stock-inventory-sql-problem/
I have try this links but the result give me total stock left in inventory .
But I want a price of each out transaction . So i have no idea to do with this.
Could you give me some example of this logic
>>  https://www.simple-talk.com/sql/performance/set-based-speed-phreakery-the-fifo-stock-inventory-sql-problem/ relate
to this example .
IF OBJECT_ID('tempdb..#StockIn') IS NOT NULL
DROP TABLE #StockIn
GO
CREATE TABLE #StockIn (
InID INT,
StockID INT,
InQty INT,
Price DECIMAL(16, 2),
tranDate DATE,
running INT
IF OBJECT_ID('tempdb..#StockOut') IS NOT NULL
DROP TABLE #StockOut
GO
CREATE TABLE #StockOut (
OutID INT,
StockID INT,
OutQty INT,
lineid INT,
tranDate DATE
INSERT #StockIn ( InID, StockID, InQty, Price, tranDate, running )
VALUES ( 1, 1, 15, 430, '2014-10-09', 1 ),
( 2, 1, 10, 431, '2014-10-10', 2 ),
( 3, 1, 15, 432, '2015-02-02', 3 ),
( 4, 2, 15, 450, '2014-08-05', 1 ),
( 5, 2, 6, 450, '2014-10-01', 2 ),
( 6, 2, 15, 452, '2015-10-02', 3 )
INSERT #StockOut ( OutID, StockID, OutQty, lineid, tranDate )
VALUES ( 1, 1, 20, 2, '2014-10-11' ),
( 2, 1, 10, 4, '2014-10-12' ),
( 3, 2, 12, 8, '2014-11-01' ),
( 4, 2, 3, 8, '2014-11-02' );

Similar Messages

  • TS1702 it says that i have to pay again to download a game from itunes.. how can i get the game in my itunes and phone? do I accept the charges and it will be re-embersed? what should I do? I have the order confirmation number etc. if you need.

    it says that i have to pay again to download it from itunes.. how can i get the game in my itunes and phone? do I accept the charges and it will be re-embersed? what should I do? I have the order confirmation number etc.

    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • How can I get the serial number for registration and instalation?

    Hello ,How can I get the serial number for registration and instalation?

    contact your local sales representative.
    You don't need a serial number to install LabVIEW.
    Registration is optional.
    Activation is needed after the evaluation period.
    Install it without number and it will work for a limited time (30days?) in evaluation mode, giving you plenty of time to decide if you want to buy it.
    Check the license manager to see the activation status of everything installed.
    LabVIEW Champion . Do more with less code and in less time .

  • Connot get it to accept cookies; privacy settings are re-set each time after I change them. How can I get the privacy setting to stick and accept cookies?

    I need to accept cookies to log into a technical site. I clear all cookies and the history and follow the instructions for setting privacy options to "Use custom settings for history" and to accept all cookies. When I go back to try logging into the site, it still tells me cookies aren't accepted. When I go back to Options-Privacy, the setting has been changed back to "Remember history" from "Use custom settings for history". I have done this about 5 times, trying various options, closing Firefox after making the change and starting it again - nothing works. How can I get the privacy settings to stay as I set them and accept cookies?

    Blocking all cookies in Safari does not work. Deleted cookies will not stay deleted. There are numerous threads on this going back years, both in these forums and elsewhere. Many claim to have submitted the issue to Apple, but I have never seen anyone post a reply.
    I have seen many suggested fixes that involve finding the cookies file, some including Terminal manipulations, and none seems to work universally. I can find noplace where Apple addresses this officially with an actual Apple-approved explanation or how-to.
    Bottom line, your browser's security features should do what they claim: delete cookies. When they come back without ever even visiting another page, this is clearly not working in the way a reasonable user would expect.
    Bottom line, Safari does not protect users' privacy in the way it pretends to and, after so many years of this issue, it appears that Apple wants it this way.
    Having spent way too much time on this, I realize the choice is between Safari which is pretty well optimized; Firefox which is a lot pokier, at least for me; and Chrome, which I assume funnels personal information directly to Google.

  • I have alot of music on my iphone 4 that i cant get on to my itunes account on the computer, when i sync the phone it doesn't transfer the music on to my computer. how can i get the music off my phone and into my itunes without it deleteing all my music?

    i put all my music on my iphone and then when i got my new computer and downloaded itunes, it wont let me transfer the music thats on to my phone.
    How do i get the music thats on my iphone on to my computer without it deleting everything?
    (please dont tell me to sync my phone or back it up as i already have and it hasnt tranfered my music).

    See Recover your iTunes library from your iPod or iOS device.
    tt2

  • How can I get the local computer's ID and IP address in Labview?

    I want to get the local computer's ID and IP address, but i found i can't do it in labview.
    Could anybody do me a favor to give me some guidance?
    Thank very much!

    Under the Communication palette, under TCP, there are two functions you need to get this info':  'String to IP' and 'IP to String.'
    1.  Drop the String to IP function on the diagram. 
    2.  Do not wire any input to it. 
    3.  Take its Output and wire it to the 'net address' input of the 'IP to String' 
    5.  Display the Output of the 'IP to String' 
    Depenging on the True/False input to the 'IP to String' function, you get the machine name versus IP address. 
    See attachemnt... guess it's easier than explaining 
    Hope this helps.
    -Khalid
    Attachments:
    ip.png ‏2 KB

  • How can i get the name of a symbol and pass to a variable?

    Hello! Is posible to get the name of a symbol and pass to a variable??
    Thanks
    Sonia

    Ok. Bravo
    Please mark this as 'Answered' - it will help others on the forum -

  • Sometimes my iphone has the music avalable but then its not there . I dont understand what to do.How can I get the music to my Iphone  and that it is there permanently

    The funny thing now is that I play music on my Iphone and I cannot see it or stop it. I have done a syncronzing yesterday and then nothing happened and later there they were all the cds. but now they are not seen on the screen and I just dont understan how the system works. I have read the instructions and tried to folow them but it has not helpt at all.

    At this point I think you should get Applejack...
    http://www.macupdate.com/info.php/id/15667/applejack
    After installing, reboot holding down CMD+s, (+s), then when the DOS like prompt shows, type in...
    applejack AUTO
    Then let it do all 6 of it's things.
    At least it'll eliminate some questions if it doesn't fix it.
    The 6 things it does are...
    Correct any Disk problems.
    Repair Permissions.
    Clear out Cache Files.
    Repair/check several plist files.
    Dump the VM files for a fresh start.
    Trash old Log files.
    First reboot will be slower, sometimes 2 or 3 restarts will be required for full benefit... my guess is files relying upon other files relying upon other files! :-)
    Disconnect the USB cable from any Uninterruptible Power Supply so the system doesn't shut down in the middle of the process.
    Then... Try putting these numbers in Network>TCP/IP>DNS Servers, for the Interface you connect with...
    208.67.222.222
    208.67.220.220
    Then Apply. For 10.5/10.6 Network, highlight Interface>Advanced button>DNS tab>little + icon.
    DNS Servers are a bit like Phone books where you look up a name and it gives you the phone number, in our case, you put in apple.com and it comes back with 17.149.160.49 behind the scenes.  
    These Servers have been patched to guard against DNS poisoning, and are faster/more reliable than most ISP's DNS Servers.
    For 10.5/10.6 Network, highlight Interface>Advanced button>DNS tab>little + icon.

  • How can i get the same colors in PS and Bridge

    My pictures is shown with stronger contrast and saturation in bridge than the original PS file in PS.
    Im trying to open the Suite Color Management in Bridge but it says that "Suite Color Management requires that a qualifying product has been launched at least onc to enable this feature". What shoud I do?

    Remember that Photoshop is showing you a rendering of the original file, while Bridge is showing you a rendering of the sRGB preview Bridge itself generates.  Color management plays a huge role in that depending on whether the file is tagged (has an embedded profile) or not.
    As for the illusory "Suite Color Management", Trevor is right in pointing out that it is utterly irrelevant if you only have Photoshop and Bridge but none of the other  applications in a suite.  Besides…
    …Inconsistency between or among applications in the artificial "suites" should come as no surprise.
    The "suite" concept is a fabrication of Adobe marketing and bean-counting types.  The engineering teams are totally independent of each other, they are not only in different buildings but in different cities and states of the American Union, even in different countries.
    The fact that they have little if any communication among them is highlighted by requests occasionally made in these forums by top Adobe engineers to let the other teams know when there are problems in one application that impact our workflow in another one.

  • How can I get the metronome to click dotted-quarters in 6/8?

    When I go from 4/4 to 6/8 the metronome goes hyper (clicks 8ths)
    This is annoying. How can I get the metronome to lay back and click dotted-quarters instead?
    -Thanks

    Working in 3/4 is not a realistic alternative to working in 6/8. Fundamentally, 3/4 and 6/8 are not the same thing at all. Basic music theory 101, yes?
    If you want to work with a dot-quarter click, set your time sig to 6/8 as you normally would. Then create your own click track by assigning the Klopfgeist to a track and recording (or penciling in) two dot quarters. One measure will do. Quantize and loop that region. You're done!
    \[EDIT] You might want to play around with the pitches and velocities of those two notes, but once you learn which notes (and velocities) sound best you're totally good to go.
    This technique (creating your own custom click track) is also useful if you wanted to work in 6/8 but alternate between 6/8 and 3/4 feel. There's an traditional Argentine rhythm (Chacarera) that uses this (thanks Jordito for the reminder of what it's called). There are other examples as well. Anyway, 6/8 is not 2/4 or 3/4. It's 6/8, just like 12/8 is not 4/4, and 9/8 isn't 3/4. My main point is that you shouldn't have to compromise in terms of editing on the grid or anything else just because Logic doesn't give you the click you need out-of-the-box. Work MUSICALLY and get Logic to bend to your will by using the technique above. Or, the one below!
    Message was edited by: iSchwartz

  • How can i get the realpath of my web application in jsf manage bean

    in jsp, i can use application.getRealPath("/")
    but in jsf how can i get the realpath in manage bean and initializean variable.
    thanks

    FacesContext aFacesContext = FacesContext.getCurrentInstance();          
    ServletContext context = (ServletContext)aFacesContext.getExternalContext().getContext();
    String rootpath = context.getRealPath("/");
    i use the code like that ,it can work , but when i click a button in my web page and call a function of java bean to read a file in "rootpath" , only odd number click it do well , even number click it do nothing and navigate to a blank page.
    how can i do that ,.
    my english is too pool ,sorry.

  • How can I get the cursor's position in a opened file and display a menu?

    Hello,
    I want to make a program by which I will be able to display a panel/pops up menu at the corsor's current position, (In any text/doc file or in the desktop, we can display a menu by right click of the mouse.) Now I want my program to do the same task.
    More clearly-
    1. First I would save some words or sentences in a file(aa.txt).
    2. Then I would open another text file/ a word/ excel/ or any other editor( bb.txt / cc.doc / dd.xls / ee.html ).
    3. While editing or writing something in the opened file, if I click the right mouse button/ press a key (ctrl+space), a menu will appear containing the sentences I saved in the file(aa.txt) previously.
    My program will tell me the cursor's position in bb.txt / cc.doc / dd.xls / ee.html that i opened. And display a menu. my problem is not reading / writing in a file.
    My problem is how can I get the cursor's position in a opened file display a menu at that position by a mouse/key action*.
    Would you please help me on this regard.
    Thanks

    DrClap wrote:
    I think the OP wants to start up an application like MS Word and then operate it from a Java program.Doesn't The Monkey's Paw do that? What a second, according to Wikipedia:
    [http://en.wikipedia.org/wiki/The_Monkey%27s_Paw]
    <quote>
    ...the paw of a dead monkey is a talisman that grants its possessor three wishes, but the wishes come with an enormous price.
    The moral of the story is contained in this description of the paw: "It had a spell put on it by an old fakir," said the sergeant-major, "a very holy man. He wanted to show that fate ruled people's lives, and that those who interfered with it did so to their sorrow."
    </quote>
    So I guess that a non-sequitor ... or is it?

  • HT4059 i have an american iPad2 (set to the UK), iOS version 6.1.2,  & iBooks version1.3.2 & can't get the price box to be selectable to purchase the book I want to buy from the iBookstore. What am I missing?????

    i have an american iPad2 (set to the UK), iOS version 6.1.2,  & iBooks version1.3.2 & can't get the price box to be selectable to purchase the book I want to buy from the iBookstore. What am I missing?????

    Backup with iTunes. If iTunes is asking you if you want to backup, say yes to that and it will backup your iPad. Have you ever synced with this computer before?
    My boilerplate response for anyone that wants to update the iOS.
    What you should do anytime that you update the device is to transfer purchases from the iPad into iTunes - File>Transfer Purchases - and you should backup the iPad as well. When you update the update the device, if something goes wrong, you can restore from the backup.
    However, iTunes should ask if you want to backup before you update, but just in case create the backup yourself before you update. The backup contains your app data and settings - along with other items - so make sure you backup first.
    If you have any other important files, you may want to transfer them to your computer as well, prior to the update.
    How to transfer purchases into your iTunes library
    http://support.apple.com/kb/HT1848
    How to backup and restore from a backup
    http://support.apple.com/kb/HT1766

  • I am having macbook air recently my iphotos did not open and was showing report apple and reopen but i came to know that by pressing alt and iphotos i open an new photo library and stored the pics but now how can i get the pics which i had in the earlier

    i am having macbook air recently my iphotos did not open and was showing report apple and reopen but i came to know that by pressing alt and iphotos i open an new photo library and stored the pics but now how can i get the pics which i had in the earlier photo please help me to recover my photos

    Well I'll guess you're using iPhoto 11:
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Repair Database. If that doesn't help, then try again, this time using Rebuild Database.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. (In early versions of Library Manager it's the File -> Rebuild command. In later versions it's under the Library menu.)
    This will create an entirely new library. It will then copy (or try to) your photos and all the associated metadata and versions to this new Library, and arrange it as close as it can to what you had in the damaged Library. It does this based on information it finds in the iPhoto sharing mechanism - but that means that things not shared won't be there, so no slideshows, books or calendars, for instance - but it should get all your events, albums and keywords, faces and places back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one.  
    Regards
    TD

  • How can i get the all values from the Property file to Hashtable?

    how can i get the all values from the Property file to Hashtable?
    ok,consider my property file name is pro.PROPERTIES
    and it contain
    8326=sun developer
    4306=sun java developer
    3943=java developer
    how can i get the all keys & values from the pro.PROPERTIES to hashtable
    plz help guys..............

    The Properties class is already a subclass of Hashtable. So if you have a Properties object, you already have a Hashtable. So all you need to do is the first part of that:Properties props = new Properties();
    InputStream is = new FileInputStream("tivoli.properties");
    props.load(is);

Maybe you are looking for