Help in designing SQL

Hi All,
I need little help in designing SQL. My input and output data is given below:
Input
Key
Date_1
Date_2
Key1
2/14/2011 5:22:35 PM
2/22/2011 3:05:13 PM
Key1
2/24/2011 1:48:07 PM
5/24/2011 4:50:16 PM
Key1
2/24/2011 1:48:59 PM
4/25/2011 3:36:19 PM
Key1
5/24/2011 5:18:19 PM
6/16/2011 3:17:40 PM
Key1
6/16/2011 3:25:42 PM
6/24/2011 1:33:13 PM
Key1
6/17/2011 1:12:54 PM
6/25/2011 5:55:55 PM
Output
Key
Date_1
Date_2
Key1
2/14/2011 5:22:35 PM
2/22/2011 3:05:13 PM
Key1
2/24/2011 1:48:07 PM
5/24/2011 4:50:16 PM
Key1
5/24/2011 5:18:19 PM
6/16/2011 3:17:40 PM
Key1
6/16/2011 3:25:42 PM
6/25/2011 5:55:55 PM
Here out of 2nd and third record of input, output is 2nd record of output and 5th and 6th record of input would come out as  4th record of output. Basically, if we overlapping duration between Date_1 and Date_2, we need to take min of Date_1 and max of Date_2 for that overlapping records. In case of no overlapping, we would simply output input record like  record 1 and 4 of input.
Out of
Key1
2/24/2011 1:48:07 PM
5/24/2011 4:50:16 PM
Key1
2/24/2011 1:48:59 PM
4/25/2011 3:36:19 PM
2/24/2011 1:48:07 PM was  min of above 2 and 5/24/20114:50:16 was max of above 2.
Similarly in other overlapping scenario:
Key1
6/16/2011 3:25:42 PM
6/24/2011 1:33:13 PM
Key1
6/17/2011 1:12:54 PM
6/25/2011 5:55:55 PM
6/16/2011 3:25:42 PM  was min of above 2 and 6/25/2011 5:55:55 PM was max of above 2.
Pls help.
Thanks.

Hi Frank.,
The above logic with NVL is not working.
My input sample is:
Key
Date_1
Date_2
Key1
2/14/2011 5:22:35 PM
2/22/2011 3:05:13 PM
Key1
2/24/2011 1:48:07 PM
5/24/2011 4:50:16 PM
Key1
2/24/2011 1:48:59 PM
Key1
5/24/2011 5:18:19 PM
6/16/2011 3:17:40 PM
Key1
6/16/2011 3:25:42 PM
6/24/2011 1:33:13 PM
Key1
6/17/2011 1:12:54 PM
6/25/2011 5:55:55 PM
I am giving create and insert statement below for creation of above data. Please see if you can help me:
CREATE TABLE test1
  KEY1          NUMBER     ,   
  DATE_1               DATE ,          
  date_2              DATE
insert into test1
values(1, TO_TIMESTAMP ('2/14/2011 5:22:35 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('2/22/2011 3:05:13 PM', 'MM/DD/YYYY HH:MI:SS AM')  ) ;
values(1, TO_TIMESTAMP ('2/24/2011 1:48:07 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('5/24/2011 4:50:16 PM', 'MM/DD/YYYY HH:MI:SS AM')  ) ;
values(1, TO_TIMESTAMP ('2/24/2011 1:48:59 PM', 'MM/DD/YYYY HH:MI:SS AM'), '' ) ;
values(1, TO_TIMESTAMP ('5/24/2011 5:18:19 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('6/16/2011 3:17:40 PM', 'MM/DD/YYYY HH:MI:SS AM')  ) ;
values(1, TO_TIMESTAMP ('6/16/2011 3:25:42 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('6/24/2011 1:33:13 PM', 'MM/DD/YYYY HH:MI:SS AM')  ) ;
values(1, TO_TIMESTAMP ('6/17/2011 1:12:54 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('6/25/2011 5:55:55 PM', 'MM/DD/YYYY HH:MI:SS AM')  ) ;
commit;
Expected output would be:
Output
Key
Date_1
Date_2
Key1
2/14/2011 5:22:35 PM
2/22/2011 3:05:13 PM
Key1
2/24/2011 1:48:07 PM
Key1
5/24/2011 5:18:19 PM
6/16/2011 3:17:40 PM
Key1
6/16/2011 3:25:42 PM
6/25/2011 5:55:55 PM
Thanks....

Similar Messages

  • Help Needed in SQL QPAC

    Hi there,
    I need some help regarding the SQL QPAC which is a built in QPAC in Adobe Livecycle Workflow. The SQL QPAC takes MYSQL as the default database. Suppose if we need to connect to the SQL Server or any other database, what is the procedure to do that.
    Suraj

    Hi Suraj
    You need to deploy a second copy of the SQL QPAC, and point it at a different datasource. The datasource is defined as a deployment parameter (it will prompt you when you deploy the new version of the qpac).
    You will also need to define the datasource in your application server. This is done in different ways for different application servers - for details, please see: standards_based_qpacs.pdf (part of the Workflow SDK), page 12, "Creating a JNDI datasource".
    Alternately, you can try out our SQLPlus QPAC. This allows you to directly specify connection url, driver, username and password. The SQLPlus QPAC does a lot of other things that the regular SQL QPAC doesn't do, such as handling multiple rows, testing your query, and outputting the data in a variety of ways.
    Details at: http://www.avoka.com/avoka/qpac_library.shtml
    Howard

  • Help in designing a Query

    Hello Everyone,
       I want you help in designing a query that involve OACT,OJDT,JDT1,OBGT and BGT1
    Actually I want a report that shows accounts Budget quarterly and its expenditure quarterly as well..
    Like shown below
    Account Name
    Budget from Jan to March
    Budget from April to June
    Budget from July to Sept
    Budget from Oct to Dec
    Expenditure from Jan to Mar
    Expenditure from Apr to June
    Expenditure from July to Sept
    Expenditure from Oct to Dec
                     Parameters would be Fiscal Year and Date range and Account name
    Can anyone please help me out in that one
    Thanks in advance

    Looking at the test data I have in these tables, it would appear impossible to join them all in one query without using UDFs...
    They don't share any columns.

  • Help with an SQL Query on the Logger

    We are running UCCE 8.5(3) and need help with an SQL query. When I run the below I would also like to see skill group information(name preferably)? Any help would be greatly appreciated!
    select * from dbo.t_Termination_Call_Detail where DateTime between '10-11-2012 00:00:00:00' and
    '10-11-2012 23:59:59:59'

    David, thanks for replying.  Unfortunitly I don't know enough about SQL to put that into a query and have it return data.  Would you be able to give an example on what the query would look like?

  • Help: APEX - PL/SQL Function

    Hello,
    i need some help with a SQL statement.
    I have the follwing Table "TABF":
    ID Number,
    B_Number varchar2(10),
    G_Type varchar2(10),
    Site varchar2(50),
    Event varchar2(50),
    Date varchar(10),
    Dataset varchar2(50),
    Mode varchar2(50),
    Topic varchar2(10),
    Parameter varchar2(10),
    Value varchar2(10)The table is filled with records which, like this:
    B Number | G-Type |Site       |Event  |Date     | Dataset   | Mode    | Topic    | Parameter | Value
    800257   |   4.2  |  USA      | Test  |18.08.08 | Pre       |MBA      | Field    | F_C       | 73,9015 
    800257   |   4.2  |  USA      | Test  |03.04.96 | BL        |MBA      | Field    | F_C       | 73,6951 
    800257   |   4.2  |  USA      | Test  |03.04.96 | BL        |MBA      | Field    | F_C       | 73,71 
    800257   |   4.2  |  USA      | Test  |18.08.08 | Post      |MBA      | Field    | F_C       | 73,7526 
    800257   |   4.2  |  USA      | Test  |18.08.08 | Pre       |MBA      | Field    | F_C       | 4,5170 
    800257   |   4.2  |  USA      | Test  |03.04.96 | BL        |MBA      | Field    | F_H       | 24,6074 
    800257   |   4.2  |  England  | Test  |03.04.96 | BL        |MBA      | Field    | F_H       | 24,62 
    800257   |   4.2  |  England  | Test  |18.08.08 | Post      |MBA      | Field    | F_H       | 24,4717  Now im looking for a SELECT statement or better a function that returns a SELECT under the following condition:
    If B_Number and Event and Date and Dataset are equal, then add 3 additional columns (Topic2, Paramter2, Value2) at the first aquivalent entry.
    Then the row can be delete/ignored. If there will be another record where B_Number,Event, Date are equal to a row above then Topic3, Paramter3 and Value 3 should be added as a new column at the first record where the conditions equals.
    And so on.....
    The result should look like this for the example above:
    B Number | G-Type |  Site     |Event  |Date     | Dataset   | Mode    | Topic    |Parameter   | Value    | Topic2   |  Parameter2  | Value2
    800257   |    4.2 |  USA      | Test  |18.08.08 | Pre       | MBA     | Field    | F_C        | 73,9015  | -        | -            | -
    800257   |    4.2 |  USA      | Test  |03.04.96 | BL        | MBA     | Field    | F_C        | 73,6951  | Field    | F_H          | 24,6074
    800257   |    4.2 |  USA      | Test  |03.04.96 | BL        | MBA     | Field    | F_C        | 73,71    | Field    | F_H          | 24,62 
    800257   |    4.2 |  USA      | Test  |18.08.08 | Post      | MBA     | Field    | F_C        | 73,7526  | -        | -            | -
    800257   |    4.2 |  USA      | Test  |18.08.08 | Pre       | MBA     | Field    | F_C        | 4,5170   | -        | -            | -
    800257   |    4.2 |  England  | Test  |18.08.08 | Post      | MBA     | Field    | F_H        | 24,4717  | -        | -            | -Hope you understand my problem and some1 can help me.
    Thank you
    Regards
    Chris
    Edited by: user11369135 on 09.07.2009 00:50

    user11369135 wrote:
    Hello,
    i need some help with a SQL statement.
    I have the follwing Table "TABF":
    Now im looking for a SELECT statement or better a function that returns a SELECT under the following condition:
    If B_Number and Event and Date and Dataset are equal, then add 3 additional columns (Topic2, Paramter2, Value2) at the first aquivalent entry.
    Then the row can be delete/ignored. If there will be another record where B_Number,Event, Date are equal to a row above then Topic3, Paramter3 and Value 3 should be added as a new column at the first record where the conditions equals.
    And so on.....
    Edited by: user11369135 on 09.07.2009 00:50if I understand correctly then you want a simple GROUP BY on B_number, Event, Date and Dataset.
    But you want additionaly show 3 columns from one of the rows that was grouped.
    This can be done using the little known KEEP syntax.
    Documentation: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions056.htm#sthref1389
    Example from the docs
    Aggregate Example
    The following example returns, within each department of the sample table hr.employees, the minimum salary among the employees who make the lowest commission and the maximum salary among the employees who make the highest commission:
    SELECT department_id,
    MIN(salary) KEEP (DENSE_RANK FIRST ORDER BY commission_pct) "Worst",
    MAX(salary) KEEP (DENSE_RANK LAST ORDER BY commission_pct) "Best"
       FROM employees
       GROUP BY department_id;
    DEPARTMENT_ID      Worst       Best
               10       4400       4400
               20       6000      13000
               30       2500      11000
               40       6500       6500
               50       2100       8200
               60       4200       9000
               70      10000      10000
               80       6100      14000
               90      17000      24000
              100       6900      12000
              110       8300      12000
                        7000       7000

  • How to design SQL server data file and log file growth

    how to design SQL DB data file and log file growth- SQL server 2012
    if my data file is having 10 GB sizze and log file is having 5 GB size
    what should be the size in MB (not in %) of autogrowth. based on what we have to determine the ideal size of file auto growth.

    It's very difficult to give a definitive answer on this. Best principal is to size your database correctly in advance so that you never have to autogrow, of course in reality that isn't always practical.
    The setting you use is really dictated by the expected growth in your files. Given that the size is relatively small why not set it to 1gb on the datafile(s) and 512mb on the log file? The important thing is to monitor it on an on-going basis to see if that's
    the appropriate amount.
    One thing you should do is enable instant file initialization by granting the service account Perform Volume Maintenance tasks in group policy. This will allow the data files to grow quickly when required, details here:
    https://technet.microsoft.com/en-us/library/ms175935%28v=sql.105%29.aspx?f=255&MSPPError=-2147217396
    Also, it possible to query the default trace to find autogrowth events, if you wanted you could write an alert/sql job based on this 
    SELECT
    [DatabaseName],
    [FileName],
    [SPID],
    [Duration],
    [StartTime],
    [EndTime],
    CASE [EventClass]
    WHEN 92 THEN 'Data'
    WHEN 93 THEN 'Log' END
    FROM sys.fn_trace_gettable('c:\path\to\trace.trc', DEFAULT)
    WHERE
    EventClass IN (92,93)
    hope that helps

  • Helping in Designing Scenario

    Hello people!
           i need some helping in designing a solution,  i'm kinda new in the PI world, and i never made BPM stuff and so...
          Here is my situation, i have 2 Webservices that i have to consume in PI
         R/3 will send information to PI
          in PI i have to Consume the first Webservice with some information and that will Response a Token,
    then i have to Merge this Token with another XML message and send to another Webservice, the i get the Response Message of this webservice and send back to R/3
        whats the best way of doing this? is it using BPM?
    this is the two Webservices i will have to use:
    http://siatepqa.suseso.cl:8888/Siatep/WSToken?wsdl
    http://siatepqa.suseso.cl:8888/Siatep/WSIngreso?wsdl
    Can anyone help me?
    Thanks!
    Edit:
    i've already read alot of BPM topics and  i think this is the way... but i'm not sure
    i want to use abap_proxy conection in r/3 > PI and the webservice connections will use SOAP/WS
    Edited by: pitoshi on Jun 9, 2010 10:57 PM

    Liang Ji,
    thanks  very mutch for your answer, this is very helpfull,
    But in:
    "R/3 send message to PI via Outbound proxy (using XI Adapter) ---> PI receive Message and execute Mapping program --> during the mapping program, you can have SOAP lookup to call first web service to get token, then you can use lookup value in your mapping, ---> Use SOAP receiver adapter to call first web service, then PI get response from it, then pass to R/3. "
    You mean " ---> Use SOAP receiver adapter to call first web service, then PI get response from it, then pass to R/3. ""
    call the Second Webservice?
    in spite of my difficulties with BPM, is this solution is better than using BPM?
    Edit: * and if any of these processes do not respond? how I treat it? *
    anyone else have any other option or tips to this scenario?
    Edited by: pitoshi on Jun 10, 2010 12:34 AM

  • How can I turn off the pop-up "Help HP Design Products You Want"? (8600 printer)

    The pop-up window "Help HP Design the Products you want" keeps returning every 5 minutes all day long
    regardless of how I respond to it!  Can this be turned Off?
    This question was solved.
    View Solution.

    What printer are you using?
    What OS do you have?
    Does it give a program name when it pops up, or does it just give you that message and a couple of options to choose from?
    -------------How do I give Kudos? | How do I mark a post as Solved? --------------------------------------------------------

  • Digital Publishing Suite Help | Layout design overview

    This question was posted in response to the following article: http://helpx.adobe.com/digital-publishing-suite/help/layout-design-overview.html

    Great Video.
    Can you have two 15 page docs for Horz and Vert formats marry them in folio, so that article 1 has a Horz and Vert orientation,article 2 the same and so on and so on right up to article 15?
    Right now it seems like I would have to break the two docs into 15 individual docs each to accomplish the Horz and Vert orientation.

  • I am making a Conference/Event program book.  Are there mac programs or apps that could help me design this?

    I am making a Conference/Event program book.  Are there mac programs or apps that could help me design this?

        I can see that this issue has been quite extensive, and frustrating, and I am so sorry for all that has happened societygirl! I would like to help you work this issue out. Please follow & send me a Direct Message, so I can get your account specifics and help finally bring this to a resolution.
    Thank you,
    MichelleH_VZW
    Follow us on Twitter @VZWSupport

  • Help me design certificate services

    Hi  i  am planning ADCertificate Services with PKI and we are going to come up with 2 data centers. Each data center has 2 domain controllers. I would like to come up with Two-Tier CA Hierarchy. Is this the right approach if certificate services
    will be hosted on three machines, the offline Root CA wll be a physical machine in datacenter2 with one second tier CA in each data center as a virtual machine. please help me design certificates services if i am going wrong.

    first of all thnx for ur reply! actually you are some what right, but what i want is that a client comes and right like this for e.g; sqr(log(sin(n)))
    then this will first go to sqr server , then to log and at the end to the sin server which means that sin server will first return the value of the n to log and after the log is computed on the value which was return by the sin server, it will go to the log server and in the end the log server returns the log of that value to the client, as this phenomenon is called grid computing. this is the what i want...
    now, where i m stuck is that i know how to make a server and a client .. but i dont know how will i interact one server to the other and returning back the value ... pls help me with some coding of this or any tutorial if u have .. i will be vary glad if u help me in this i will really appreciate your corporation!
    thank you! waiting for ur reply
    Danish

  • Help on java.sql.Types class

    Hai Friends ,
    I want some help on java.sql.Types class .
    What is the use of the above class ?
    Some details about this class.

    Good Morning Yekesa
    First of all i would like to thank U for looking into my problem.
    I am using java.sql.Types.OTHER for
    {"?=CALL(storedprocedurename.functionname(?))"}
    registerOutParameter(1,javal.sql.Types.OTHER)
    setString(2,"user")
    here the
    second parameter passes an argument to function name ( viz. username say "user")
    and the function will return the ref cursor as follows:
    // declaration in pl/sql procedure
    begin
    rc ref cursor
    open rc for select * from ss_user where login_name="user";
    return rc;
    end
    now the stored procedure has a return value (i.e. stored function) which it needs to register as
    registerOutParameter(1,javal.sql.Types.OTHER)
    and it finally results in the following errors :
    Loading driver
    Before conn stmt
    After conn stmt
    Calling Stored procedure
    Stored procedure called
    java.sql.SQLException: Invalid column type
    at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:243)
    at oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.java:2487)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:64)
    at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:54)
    at sptest.<init>(sptest.java:28)
    at sptest.main(sptest.java:49)
    T couldn't understand why it is saying Invalid Column Type because its working fine with both
    java.sql.Types.INTEGER
    and
    java.sql.Types.VARCHAR
    Pl help me at the earliest as i have wasted a lot of time on it.
    pl mail me in detail at [email protected]
    bye then
    bansi
    null

  • Please help in designing...

    Hey Folks,
    A new bee to Flex...Want to design and develop a flexible GUI in flex..Can any one help in designing the GUI?
    Requirements
    Database
    I have four tables namely TableId, ColumnName, ColumnValue, PartyColumnValue
    TableId
    tableId int
    tableName  varchar
    eg :-
    10
    Test
    ColumnName
    columnId int
    tableId int
    columnName Varchar
    eg:-
    1001
    10
    Col1
    ColumnValue
    valueId int
    columnId int
    tableId int
    valueName Varchar
    eg:-
    100101
    1001
    10
    val1
    PartyColumnValue
    id int
    valueId int
    columnId int
    tableId int
    In the above manner I am storing the table names, column Names and column values
    Flex Requirement(GUI)
    On GUI there will be one combobox in which user has the option of selecting the table name
    Once table is selected
    1. Dynamic Table(DATAGRID in flex) should be displayed on GUI in which the columns will be the column name from the ColumnTable and each row should be the combobox in which the values will be multiple pertaining to the ColumnId and tableId.
    2. Each row should be having the option to "save" individual row means the last column will be save button, it will get persisted in the PartyColumnValue table.
    3. There should be option to save all the rows means "Save All" button to save all the rows it will get persisted in the PartyColumnValue table.
    4. Once i saved the invidual row or all rows and then again if user selects the table from the combobox he should be able to see the persisited values.
    5. There should be one "Add Column" button which will add the column by opening the popup and asking for the default values.
    Can anyone help me in acheving this functionality?
    Thanks In Advance!!!

    Can anyone help without money?

  • Help needed to create Drop down help through Design layer for attribute

    Hi All,
    Has anybody created a Dropdown help through Design layer for standard field, there we have check Box ............
    Please Help me to know this ASAP....
    Edited by: Pankaj Gupta on Feb 26, 2010 10:52 AM

    Hi,
    Here is the exampel Program, i am sending the code for a Paramter, If you want this for the Select-options, then you need to have the paramer name as PS_PARM-LOW and you need to write the smae logic again for PS_PARM-HIGH to get the List box for the select-option
    REPORT ZLIST.
    TYPE-POOLS: VRM.
    DATA: NAME  TYPE VRM_ID,
          LIST  TYPE VRM_VALUES,
          VALUE LIKE LINE OF LIST.
    PARAMETERS: PS_PARM(10) AS LISTBOX VISIBLE LENGTH 10.
    AT SELECTION-SCREEN OUTPUT.
    NAME = 'PS_PARM'.
    VALUE-KEY = '1'.
    VALUE-TEXT = 'LINE 1'.
    APPEND VALUE TO LIST. VALUE-KEY = '2'.
    VALUE-TEXT = 'LINE 2'.
    APPEND VALUE TO LIST.
    CALL FUNCTION 'VRM_SET_VALUES' EXPORTING ID = NAME VALUES = LIST.
    START-OF-SELECTION.
    WRITE: / 'PARAMETER:', PS_PARM.

  • Someone please help me Design the database of bill of materials

    I want to design the database of bill of materials which contain item and amount.
    So the amount of child will depend on amount of parent in term of ratio. For example
    A(1)               A(2)
    |         ---->     |
    B(2)               B(4)
    My problem is when i try to add the parent and child . Let A is the parent of B , If i try to add A to be the child of C
    I want B to come along with A as well. For example
    A                       C
    |     C  --->        |           For this I have to store the relation of all item in  my list to check that this item have a child or not if yes
    B                             A              The child must come along with its parent , What the Er-diagram
    should be for all of my requirement?
                                    |
                                    B

    >I want B to come along with A as well. For example
    You can do that, but that is not automatic. You need to do some programming.
    It is better to use hierarchyid representation of the tree over traditional FK referencing.
    Tree using hierarchyid example:
    http://www.sqlusa.com/bestpractices2008/orgchart/
    BOL: "Model Your Data Hierarchies With SQL Server 2008
    .....The manufacturing system behind automobiles; the organization of a country into states, counties, cities, and postal codes; the description of a home entertainment system—what do these things have in common? The simple answer is that each
    describes a hierarchy.
    SQL Server 2008 supports a new data type, HierarchyID, that helps solve some of the problems in modeling and querying hier­archical information. I will introduce you to this data type by discussing a pattern commonly used in manufacturing
    known as bill of materials (BOM), or bills. Starting with a brief discussion of BOMs, I will illustrate how this kind of data can be modeled. I will also present an implementation of this model in SQL Server 2005. Then I will show you how the HierarchyID data
    type can be used to implement the model in SQL Server 2008.
    Hierarchical Data
    Automobiles are amalgamations of many components, such as engines, drivetrains, electronics, and steering. In the United States, our geographic territories are divided into states and are then sub-divided into jurisdictions called counties.
    Counties are then further subdivided in different ways by different agencies. The United States Census Bureau, for example, composes them from Census Tract Areas. The U.S. Postal Service routes mail delivery by Zone Improvement Plan (ZIP) codes. Geographic
    information systems (GIS) may aggregate census tracts and ZIP codes together to provide users with a familiar spatial reference for an area.
    A recent trip to a local electronics store to evaluate a replacement home entertainment system pointed to a similar sort of hierarchical system—all the combinations of possible components and options left my head spinning! I wondered
    how such systems could be modeled and implemented in a database system.
    The relationship between an automobile and its engine represents a hierarchy: the automobile contains the engine. The relationship is the same for the drivetrain, the electronics, and the steering. The relationship is containment. A
    similar hierarchy can be observed in the relationship between the different groupings of geographic or census data.
    Hierarchies exist everywhere, yet implementing them in the context of a relational database frequently proves to be a challenge. A typical approach is to represent the hierarchy using a parent/child relationship with one or more tables.
    While this approach certainly works in many cases, it has a few shortcomings. Such solutions must carefully consider how the referential integrity will be maintained. And while querying the depth and breadth of such tables was considerably simplified in SQL
    Server 2005 with the introduction of recursive common table expressions, writing queries against these types of tables can still be problematic when joins against many tables are required.
    A Bill of Materials Problem
    A few years ago I was working on a system being developed by a manufacturing company to help their dealers specify the components needed to build center-pivot irrigation systems. The software produced a list of components needed to custom-build
    the desired pivot (the totality of a center-pivot irrigation system is simply referred to as a pivot within the industry). The required components were determined based on geography, soil type, and the intended crops planted in the areas to be covered as well
    as the hydrologic and structural considerations of the device itself.
    Underpinning the solution would be a SQL Server database. The purpose of the database was to store information about the components available to build the pivot. However, when we generated the specification for manufacturing, we needed
    to identify those components as BOMs.
    Some bills represented a collection of physical parts that would be assembled into a system component. For example, every pivot needed a pump to draw water from a well into the system. That pump might be electrically powered, meaning
    it needed a transformer and fuse box, too. Or the pump might be fuel powered, meaning it needed a tank, a fuel pump, and hoses to connect the pump to the tank. In either case, the required parts for the pump would be listed in a pump bill.
    The bill for a complete pivot would include a collection of other bills. For example, a standardized pivot might consist of a tree of bills for the pump, another tree of bills for the spans of pipe used to deliver water, and bills for any other equipment
    needed to build that pivot system."
    LINK: http://msdn.microsoft.com/en-us/magazine/cc794278.aspx
    Kalman Toth Database & OLAP Architect
    SELECT Query Video Tutorial 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

Maybe you are looking for