Query for Tracking Item

Hi There,
We have a table in Database with Columns ( Installed, Removed, Transaction Date ) , that table tracks the Parts when it is installed in store and when that part was removed from store with Transaction Dates
So from below example how to get the "Part A" install and Removal Dates ?
Please Help !!
Thanks,
Learning Bee !!
Dotnet.Explorer

Please try this code:
IF OBJECT_ID('dbo.Track') IS NOT NULL
DROP TABLE dbo.Track;
GO
CREATE TABLE dbo.Track
Installed NVARCHAR(10) ,
Removed NVARCHAR(10) ,
TransactionDate INT
GO
INSERT INTO dbo.Track
( Installed, Removed, TransactionDate )
VALUES ( N'Part A', NULL, '2007' ) ,
( N'Part X', N'Part A', '2008' ) ,
( N'Part A', N'Part X', '2009' ) ,
( N'Part Y', N'Part A', '2010' ) ,
( N'Part A', N'Part Y', '2011' );
GO
WITH NewTrack
AS ( SELECT * ,
ROW_NUMBER() OVER ( ORDER BY TransactionDate ) AS Rn
FROM dbo.Track
SELECT T1.Installed AS Part ,
T1.TransactionDate AS [Installed Date] ,
T2.TransactionDate AS [Removerd Date]
FROM NewTrack AS T1
LEFT JOIN NewTrack AS T2 ON T1.Installed = T2.Removed
AND T2.Rn = T1.Rn + 1
ORDER BY Part ;
T-SQL Articles
T-SQL e-book by TechNet Wiki Community
T-SQL blog

Similar Messages

  • Query For Open Items

    Hi,
    We are trying to create a query for the open items (purchase orders ) in order to add some fields useful for users.
    Would you be able to advise with the query needed to show us only the open items?
    Best regards,
    MB

    Hi,
    Try this one:
    Select distinct t1.cardcode as Vendor, t1.CardName as Name, t1.docnum as PO#, t0.itemcode, t0.Dscription, t0.OpenQty as 'Open Qty', t0.linenum Row#, t1.DocCur as Currency, t0.price as 'Purchase Price', t0.whscode, t1.taxdate as "PO Date"
    from dbo.por1 t0
    inner join dbo.opor t1 on t1.docentry = t0.docentry
    where t1.DocType = 'I' and t0.linestatus = 'O'
    order by t1.docnum Desc, t0.linenum
    Thanks,
    Gordon

  • Query for Tracking the database

    Hai
    i am entering Some process in Client Application. Each process some records get updated in database tables.
    How can i fiind it? for example if i am updating engine menu of the application. engine table and some other tables are get updated. i dont have source code of application with me. how can i monitor that what are the tables get affected in the database.
    we have to work from database side.
    one thing i can do... write the query for table and count(*) after every process so that i can get which table get affected by identifying the row count.
    but i want only particular table get affected on particular process.
    Kindly give ur suggesiton
    S

    Well, you can connect as privileges user and issue:
    ALTER SYSTEM SET SQL_TRACE=TRUE;This will enable trace of every user session. So it is better if you are the only one using application and database. To find trace files location issue:
    SQL> select value from v$parameter where name = 'user_dump_dest';Trace files will have all SQL statements issued by a session. You can either read them raw (trace files are text files) or use Oracle supplied tkprof utility to format them.
    SY.
    P.S. Do not forget to turn off trace after you are done:
    ALTER SYSTEM SET SQL_TRACE=FALSE;

  • Using SQL Query for page item source does not insert populated value

    Hi All,
    Following are the attribute details of a certain page item on an edit form:
    Display As: Text Field
    Page Item Source Type: SQL Query
    Source value Expression: SELECT a from tab where id = 'ABC'
    Although the field appears populated on the screen, but the value is not inserted in the table.
    Can anyone help on this?
    Thanks in advance,
    Annie

    Annie:
    One solution is to define a pl/sql function that given a date will return the 'run-date'. Something like create or replace function get_prod_date(p_date in date) return date is
    retval date;
    begin
    select run_date into retval from tab_x where run_date=p_date;
    return retval;
    end;Change the Source Type for the page-item back to 'Database Column'
    Set Source value or expression to the 'database column name'
    Set 'Post calculation computation' to be
    get_prod_date(:pxx_date)
    Varad

  • Query for Billable item form MTL_SYSTEM_ITEMS_B for BOM billing item

    Hi All,
    I want to write query to get billing item from mtl_system_items_b for BOM ...Can anyone give me the idea for accessing the billing item..
    In BOM
    Routings - Resources(form) - Billing Item (Field) and Outside Processing Item (Field)LOV...i Want to know query to access these items..
    Thanks
    Raman Sharma
    Edited by: 929841 on Apr 24, 2012 6:06 AM

    Obtain FRD log file to find out why the trigger is fired twice.
    R12: Forms Runtime Diagnostics (FRD), Tracing And Logging For Forms In Oracle Applications (Doc ID 438652.1)
    Steps To Take FRD Trace in 11.5.10 & R12 (Doc ID 867943.1)
    R12: How To Create An FRD (Forms Runtime Diagnostic) Log Using Forms 10g (Doc ID 445166.1)
    How To Collect And Use Forms Trace (FRD) in Oracle Applications Release 12 (Doc ID 373548.1)
    Thanks,
    Hussein

  • Warranty related query for sales item

    hi I need a report for checking an sales item is under warranty or not & also I want to know the status of the products which comes under warranty is in open state or closed state Regards, K.Ramasamy

    Hi,
    Try this query:
    SELECT T0.[ItemCode], T0.[ItemName], T1.[TmpltName], T1.[Deleted] FROM OITM T0  inner join OCTT T1 on  T0.[WarrntTmpl]  =  T1.[TmpltName] WHERE T0.[SellItem]  = 'y'
    Thanks.

  • Query for Total Items

    Hi Experts..
    I need a query to find the total  items  sold in a particular period for an particular item.
    Pls help me in finding the query.
    Regards,
    Vamsi.
    Edited by: Parimis on Jan 20, 2010 5:10 AM

    Hi Vamsi,
    Check the thread,
    Help With Monthly Sales Query
    Regards,
    Madhan.

  • Query for exact item name for CAL required

    Hi,
    We are e-businessoft, reseller for Microsoft softwares.
    One of the customer has recently purchased windows server and now wants to purchase some user CALs. Few users will do mstsc of WinServer from within the
    premises and few customers will do the mstsc from remote location, a different city. Remote user will login via internet connection into the LAN and then do mstsc
    of WinServer.
    Please tell me exactly what products has to be purchased to facilitate this. I have suggested the below:
    1. WinSvrCAL 2012 SNGL OLP NL UsrCAL
    2. WinRmtDsktpSrvcsCAL 2012 SNGL OLP NL UsrCAL
    If this is correct, then please guide on how exactly this works? For example, The user doing mstsc from within premises requires item 1 only and users doing mstsc
    from different city requires item 2 only, or both 1 and 2 is required in both case.
    The terminal server services gives a countdown of 120 days from date of installation and ultimately expires and all connections thru mstsc stops. And then the
    server is reinstalled. So one major concern is whether purchase of these CALs will stop this inconvinience for ever?
    Please reply asap. CAL requirement is very urgent but can not proceed unless this clarity comes from you.

    Hi,
    Resellers should contact MSFT Partner Support for assistance.
    In general, the scenario you describe requires both Windows Server CAL and also RDS CAL for each user/device.
    This is because an RDS/TS CAL is required for correctly licensed use of RDS/TS, and in addition, because RDS/TS is used to gain access to Windows Server services/features, a Windows Server CAL is also required.
    (there are different scenarios which may apply, depending upon the edition of Windows Server being used, and also, it may be less expensive, depending on the size/scale of the scenario, to instead consider CAL Suite options)
    (also, note that if the Windows Server is offering MS Office, that requires Office licensing to be addressed. Also consider if the RDS/TS will allow the users/devices to consume MS Exchange or MS SharePoint or MS SQL, additional CALs for those products may
    be required)
    Don
    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable.
    This helps the community, keeps the forums tidy, and recognises useful contributions. Thanks!)

  • Performance of query for getting item revisions

    Hi All,
    The following query took several minutes in an environment with about 7,500,000 item revisions :
    SELECT
    MIR.INVENTORY_ITEM_ID
    , MSI.CONCATENATED_SEGMENTS ITEM_NUMBER
    , MIR.ORGANIZATION_ID
    , MP.ORGANIZATION_CODE
    FROM
    MTL_ITEM_REVISIONS_VL MIR
    , MTL_PARAMETERS MP
    , MTL_SYSTEM_ITEMS_VL MSI
    WHERE
    (MIR.INVENTORY_ITEM_ID = p_Item_ID OR MSI.CONCATENATED_SEGMENTS = p_Item_Number)
    AND (MIR.ORGANIZATION_ID = p_Org_ID OR MP.ORGANIZATION_CODE = p_Org_Code)
    AND MP.ORGANIZATION_ID = MIR.ORGANIZATION_ID
    AND MIR.INVENTORY_ITEM_ID = MSI.INVENTORY_ITEM_ID
    AND MIR.ORGANIZATION_ID = MSI.ORGANIZATION_ID ORDER BY EFFECTIVITY_DATE, REVISION DESC;
    If changing this query to the following, it takes less than a second:
    SELECT
    MIR.INVENTORY_ITEM_ID
    , MSI.CONCATENATED_SEGMENTS ITEM_NUMBER
    , MIR.ORGANIZATION_ID
    , MP.ORGANIZATION_CODE
    FROM
    MTL_ITEM_REVISIONS_VL MIR
    , MTL_PARAMETERS MP
    , MTL_SYSTEM_ITEMS_VL MSI
    WHERE
    MSI.CONCATENATED_SEGMENTS = p_Item_Number
    AND MP.ORGANIZATION_CODE = p_Org_Code
    AND MP.ORGANIZATION_ID = MIR.ORGANIZATION_ID
    AND MIR.INVENTORY_ITEM_ID = MSI.INVENTORY_ITEM_ID
    AND MIR.ORGANIZATION_ID = MSI.ORGANIZATION_ID ORDER BY EFFECTIVITY_DATE, REVISION DESC;
    Can anyone explain the extreme difference in performance between these two queries?
    Thanks & Regards
    Carolin

    They don't look logically equivalent to me.
    Here are the differences:
    WHERE  (MIR.INVENTORY_ITEM_ID = p_Item_ID
            OR MSI.CONCATENATED_SEGMENTS = p_Item_Number)
    AND    (MIR.ORGANIZATION_ID = p_Org_ID
            OR MP.ORGANIZATION_CODE = p_Org_Code)
    vs
    WHERE  MSI.CONCATENATED_SEGMENTS = p_Item_Number
    AND    MP.ORGANIZATION_CODE = p_Org_CodeIf they aren't logically equivalent there's no point in comparing the performance.

  • Need Query for Item Relationship of Oracle Apps

    Hello Team,
    I need the Query to select the Item Relationship.
    In Oracle Apps we have different tyes of Structure
    ItemA -> ItemB
    ItemB -> ItemC
    ItemC -> ItemD
    ItemG -> ItemH
    ItemK -> ItemL
    ItemW -> ItemQ
    and this also is possible (meand many to one relationship)
    ItemA -> ItemB
    ItemB -> ItemC
    ItemC -> ItemD
    ItemT -> ItemD
    and in the Select Query i want the below result
    ItemA -> ItemB 1
    ItemB -> ItemC 2
    ItemC -> ItemD 3
    ItemG -> ItemH 1
    ItemK -> ItemL 2
    ItemW -> ItemQ 1
    and this also is possible (means many to one relationship)
    ItemA -> ItemB 1
    ItemB -> ItemC 2
    ItemC -> ItemD 3
    ItemT -> ItemD 1
    means i want the Hierarchy number also
    Please help me to in order to get the relationship by sql query.
    Kind Regards,

    thanks for the quick response and i would love to spend time perusing the forum for this question but i didn't have time today.  i'll do that now though.
    what i'm mostly interested in is a chronological view (lastUpdateDate) of the change to pricing for an item in the system.  there is a lot of activity in our system around price changes for promotions and i want to keep track of when it's changed in the source system and pair that with our other downstream systems.
    i'm assuming we can add this functionality through a udf some way or maybe sp_TransNotification proc?

  • Re:Query for Stock Statement for a particular item..!!!!

    Dear SAP Experts,
    I need a stock statement query  for a particular item which contains:
    1.ItemCode
    2.Item Description
    3.Item Price
    4.Opening
    5.Receipts
    6.Issues
    7.Closing
    8. Value
    The selection criteria are:
    1.Warehouse code
    2.Item Name
    3.Posting Date
    Plz give me a good solution for this issue.
    With Regards,
    Revathy

    Check this
    Declare @FromDate Datetime
    Declare @ToDate Datetime
    set @FromDate =
        (Select min(S0.Docdate) from OINM S0 where S0.Docdate >='[%0]')
    set @ToDate =
        (Select max(S1.Docdate) from OINM S1 where S1.Docdate <='[%1]')
    select * from
        SELECT T0.itemcode,
        min(T0.Dscription) as 'Item Description',
        min(B1.ItmsGrpNam) as 'Item Group', W1.Whscode, C1.Location,
        (isnull((
            Select sum(isnull(inqty,0))
            from OINM O1
            where O1.itemcode=T1.itemcode
            and O1.Warehouse=W1.Whscode
            and O1.docdate<@FromDate ),0)-
        isnull((
            Select sum(isnull(outqty,0))
            from OINM O1
            where O1.itemcode=T1.itemcode
            and O1.Warehouse=W1.Whscode
            and O1.docdate<@FromDate),0)
        ) as [Opening Stock],
        isnull((
            Select sum(isnull(inqty,0))
            from OINM O1
            where O1.itemcode=T1.itemcode
            and O1.Warehouse=W1.Whscode
            and O1.docdate>=@FromDate
            and O1.docdate<=@ToDate and O1.inqty>0
            and O1.transtype in (20,18)),0
        ) as [Purchase Quantity],
        isnull((
            Select sum(isnull(outqty,0))
            from OINM O1
            where O1.itemcode=T1.itemcode and O1.Warehouse=W1.Whscode
            and O1.docdate>=@FromDate and O1.docdate<=@ToDate
            and O1.outqty>0 and O1.transtype in (21,19)),0
        ) as [Purchase Return Quantity],
       isnull((
            Select sum(isnull(outqty,0))
            from OINM O1
            where O1.itemcode=T1.itemcode and O1.Warehouse=W1.Whscode
            and O1.docdate>=@FromDate and O1.docdate<=@ToDate and O1.outqty>0
            and O1.transtype in (13,15)),0
        ) as [sale Quatity],
        (isnull
            Select sum(isnull(inqty,0))
            from OINM O1
            where O1.itemcode=T1.itemcode and O1.Warehouse=W1.Whscode
            and O1.docdate<=@ToDate),0
            isnull((
                Select sum(isnull(outqty,0))
                from OINM O1
                where O1.itemcode=T1.itemcode and O1.Warehouse=W1.Whscode
                and O1.docdate<=@ToDate),0)
        ) as [Closing Stock]
        FROM OINM T0
        INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode
        INNER JOIN OITW T2 ON T1.ItemCode = T2.ItemCode
        INNER JOIN OITB B1 ON T1.ItmsGrpCod=B1.ItmsGrpCod
        INNER JOIN OWHS W1 ON T2.WhsCode = W1.WhsCode
        INNER JOIN OLCT C1 ON W1.Location=C1.Code
        Group by T1.itemcode, T0.Itemcode, W1.WhsCode, C1.Location
    ) a
    where (a.[Opening Stock]
            +a.[Purchase Quantity]
            + a.[Purchase Return Quantity]
            +a.[sale Quatity]+a.[Closing Stock]
           ) !=0
    Regards,
    Bala

  • Query for Price difference account when item is not sold but not on stock

    Hi Experts!
    One of my clients accountant requires a report which will help for what to do with the balance of the price difference account.
    At the and of the year there are some postings on this account, but not every item that hadnt been on stock when A/P Invoice arrived were sold. Some item were waistrel and put into a waistrel warehouse, but not sold.Some item were sent back to the supplier, but not sold.
    Is it possibble to make a query for knowing where to post the balance of the price difference account? Not all should be post to the Cost of goods sold.
    Thank you in advance!

    Hi,
    The query is possible.  However, it is a complicated one. It is also need to involve detailed analysis to your transaction histories.  You may start from OINM table to check.
    Thanks,
    Gordon

  • How to create ABAP Query for vendor open items

    HI,
    My client has requested me to create ABAP Query for vendor open items . So that it will be usefull for the users . Could anyone help me with this. I will assign you points.Thanks in advance.

    Hello,
    Use Table BSIK <Open Items of AP > & BSAK <AP Cleared items>......
    For Query you can use SQ01.
    USE BSID & BSAD for AR open/clear items...
    LFA1, LFB1 are vendor master data tables
    This is FYI
    Hope this helps.
    Rgds
    Rajendra

  • What is the best way to query planned orders or work orders for make items and identify the buy component that is short for supply and vice versa?

    What is the best way to query planned orders or work orders for make items and identify the buy component that is short for supply and vice versa?

    What is the best way to query planned orders or work orders for make items and identify the buy component that is short for supply and vice versa?

  • Query to see all BP's with a special price for an item

    Hi There,
    I'm currently still learning the product and have been tasked with finding this out, so please bear with me and let me know if there is further information that is required.
    I have a customer running SAP B1 2007 who wishes to produce a report detailing all of the BP's that have a special price for an item. 
    Therefore it would ideally show the item number, all BP's who have a special price and what that price is.
    Is there a standard report that can be run for this?  Or would a query have to be defined?
    Any help would be appreciated.

    Hi,
    AFAIK, no standard report for this. But need not to worry, you just need
    SELECT ItemCode,CardCode,Price FROM OSPP ORDER BY ItemCode,CardCode
    above simple query to cater your need.
    Best Regards,
    Hendry Wijaya

Maybe you are looking for

  • How to open a page  and closing source page in jdev 10.1.3.3

    how to open a page and closing source page in jdev 10.1.3.3. for example. From page 'A' , we are opening a page 'B' and closing the page 'A'. how this can achived.Please let me know

  • Can't find new iPhoto folders in finder

    Hello - when I create a new folder in iPhoto I expect then to be able to find it and any contents through the Finder. Yet this does not happen on my Macbook. Does anyone have any idea what is wrong here?

  • Cannot create editable region on php page

    I was successful on the html page; to select the text and create editable region. But when I select the same text on the php page; I get the error message: "Selection is outside the body tag. Select the text inside the body tag." www.ndccalliance.org

  • Directory Issues on External Drive?

    I have a Mercury Elite Pro 160GB external drive, and sometimes it won't mount. Disk Utility and DiskWarrior say there's no problem. If there's corruption, does using Disk Utility to erase the drive also rewrite a new Directory? A Mac tech told me tha

  • FRM-40735 WHEN BUTTON PRESSED trigger raised unhandled exception ORA-29282

    Hi All, while entering data in EAM forcaste workorder in maintenance workbench am getting this error FRM-40735 WHEN BUTTON PRESSED trigger raised unhandled exception ORA-29282 check google and oracle forums and checked versions of pll and plx (as men