How to model this data

In the sample data below, there are rows that contain header names, followed by a row with the data.
The problem is that some of the "header" column values change.  They represent "sizes" boxes.
Name | BoxType | Color | Qty | 45 | 11 | 13.5
Compx | F | Red | 32 | 1 | 0 | 34
Name | BoxType | Color | Qty | 75 | 11 | 12.5
QuickMartZ | G | Blue | 68 | 13 | 7 | 77
Name | BoxType | Color | Qty | 75 | 11 | 45
QuickMartZ | F | Blue | 22 | 17 | 72 | 12
How could I model this data or re-shape it into a schema such as
Table
=========
AccountName
BoxType
Color
Qty
Size
Ultimately I need to be able to extract a "rolled up" count of the boxes by size and their quantity
Something like this
AccountName
BoxType
Color
Qty_Size1
Qty_Size2
Qty_Size3
Qty_Size4
Qty_Size5
Qty_SizeN...

Without some value which links the two rows together (other than the order of rows how do we know the box in the line above Compx belongs to it?) I don't think this is going to be possible as a set based solution.
You could use a cursor to move through the rows RBAR:
DECLARE @table TABLE (name VARCHAR(20), boxType VARCHAR(20), color VARCHAR(20), qty VARCHAR(4), col1 INT, col2 INT, col3 FLOAT)
INSERT INTO @table (name, boxType, color, qty, col1, col2, col3)
VALUES
('Name', 'BoxType', 'Color', 'Qty', 45, 11, 13.5),
('Compx', 'F', 'Red', '32', 1, 0 , 34),
('Name', 'BoxType', 'Color', 'Qty', 75, 11, 12.5),
('QuickMartZ', 'G', 'Blue', '68', 13, 7 , 77),
('Name', 'BoxType', 'Color', 'Qty', 75, 11, 45),
('QuickMartZ', 'F', 'Blue', '22', 17, 72, 12)
DECLARE @name VARCHAR(20), @boxType VARCHAR(20), @color VARCHAR(20), @qty VARCHAR(4), @col1 INT, @col2 INT, @col3 FLOAT,
@pname VARCHAR(20), @pboxType VARCHAR(20), @pcolor VARCHAR(20), @pqty VARCHAR(4), @pcol1 INT, @pcol2 INT, @pcol3 FLOAT
DECLARE @products TABLE (name VARCHAR(20), boxType VARCHAR(20), color VARCHAR(20), qty VARCHAR(4), size1 FLOAT, size2 FLOAT, size3 FLOAT)
DECLARE @boxes TABLE (name VARCHAR(20), boxType VARCHAR(20), size1 FLOAT, size2 FLOAT, size3 FLOAT)
DECLARE c1 CURSOR
FOR SELECT *
FROM @table
OPEN c1
FETCH c1 INTO @name, @boxType, @color, @qty, @col1, @col2, @col3
WHILE @@FETCH_STATUS <> -1
BEGIN
IF @name = 'name'
BEGIN
SET @pname = @name
SET @pboxType = @boxType
SET @pcolor = @color
SET @pqty = @qty
SET @pcol1 = @col1
SET @pcol2 = @col2
SET @pcol3 = @col3
END
IF @name <> 'name'
BEGIN
INSERT INTO @products (name, boxType, color, qty, size1, size2, size3) VALUES (@name, @boxType, @color, @qty, @col1, @col2, @col3)
INSERT INTO @boxes (name, boxType, size1, size2, size3) VALUES (@name, @boxType, @pcol1, @pcol2, @pcol3)
END
FETCH c1 INTO @name, @boxType, @color, @qty, @col1, @col2, @col3
END
CLOSE c1
DEALLOCATE c1
SELECT *
FROM @products
SELECT *
FROM @boxes

Similar Messages

  • HT4847 How i take an old back form my old iphone to my new iphone?!when i acces icloud from my phone and go to manage storage i have 4 back up for diferent phone how can acces this data?!

    How i take an old back form my old iphone to my new iphone?!when i acces icloud from my phone and go to manage storage i have 4 back up for diferent phone how can acces this data?!

    Thanks very much!
    Although I had to add everything again to the playlist, at least I can just copy it over in future!

  • How to set this DATS parameter

    Hi Pros,
            I am calling function 'HR_FORMS_TIM_GET_B2_RESULTS' in the program , its input parameter is BEGDA, I transfer a date variable to BEGDA, but does not work. can not get any data. but if I run this function in SE37, I input date '20140807', successfully get result.  please tell me how to set this DATS parameter?

    Hi,
    You might be passing the date in '12.12.2014' or '12/12/2014' format. Please
    use the function module 'CONVERSION_EXIT_BEGDA_INPUT' to convert the date
    to internal format and then pass it to the function module.
    Thanks

  • How to Achieve this Data Load into Cube

    Hi Experts,
    Could you please update me on how to achieve this
    I got a History data (25-35 Million Records) for about 8 years to be loaded to BW.
    What is the best approach to be followed
    1) Load everything into one cube and create aggregates or
    2) Create 4 different cubes (with same data model) and load load 2 years of data into each cune (2Years * 4 Cubes = 8 Years Data) and develop a multicube on top of 4 cubes
    If so how can i load data into respective cubes
    Ex: Lets assure i got data from 31.12.2007 to 01.01.2000 which is 8 years of data
    Now i created 4 Cubes--C1,C2,C3,C4 & C5
    How can i specifically
    load data from 01.01.2000 to 31.12.2001 (2 Years) to C1
    load data from 01.01.2002 to 31.12.2003 (2 Years) to C2
    load data from 01.01.2004 to 31.12.2005 (2 Years) to C3
    load data from 01.01.2006 to 31.12.2007 (2 Years) to C4
    load data from 01.01.2008 to 31.12.2010 (2 Years) to C5 (Currently Loading)
    Please advise the best approach to be followed and why
    Thanks

    If you already have the cube C5 being loaded and the reports are based on this cube, then if you donot want to create additional reports, you can go ahead and load the history data into this cube C5.
    What is your sourcesystem and datasource?. Are there selection conditions (in your infopackage) available to specify the selections? If so, you can go ahead and do full loads to the current cube.
    For query performance, you can create aggregates on this cube based on the fiscal period / month / year ( whichever infoobject is used in the reports)
    If your reports are not based on timeperiod, then multicube query will work as parrallelized sub queries and so there will be 4 dialog processes occupied on your BW system everytime the query is hit.
    Also any changes that you want to make in cube will have to be copied to all cubes, so maintenance may be a question.
    If there are enough justification, then approach 2 can be taken up

  • How to model this situation?

    Hi experts,
    I am BW 3.5. I am working with PS. I need to model the next example:
    Project 1
    Hs. % (Hs*%) % Real
    Phase 1 37.2
    Sub Phase 1 37.2
    Sub Sub Phase 1 42.8
    Ítem 1 10 0% 0(10 * 0 / 100) 0%
    Ítem 2 5 100% 5 (5 * 100 / 100) 100 %
    Ítem 3 20 50% 10(20 * 50 / 100) 50 %
    Sub Sub Phase 2 0.33
    Ítem 1 15 10% 1.5(15 * 10 / 100) 1.5 %
    Ítem 2 25 50% 12.5(25* 50 / 100) 12.5 %
    Ítem 4 15 30% 4.5(15 * 30 / 100) 4.5 %
    This is a hierarchy!!!
    The Sub Sub Phase X percentage is: ((Hs*%)/100) / Hs
    Hs (Hs*%)
    Item 1 10 0(10 * 0 / 100)
    Item 2 5 5(5 * 100 / 100)
    Item 3 20 10(20 * 50 / 100)
    Total 35 15
    Sub Sub Phase 1 % = 15 / 35 = 42.8
    The Sub Phase X percentage is: ((Hs*%)/100) / Hs
    Hs (Hs*%)
    Item 1 10 0 (10 * 0 / 100)
    Item 2 5 5 (5 * 100 / 100)
    Item 3 20 10 (20 * 50 / 100)
    Item 1 15 1.5(15 * 10 / 100)
    Item 2 25 12.5(25* 50 / 100)
    Item 4 15 4.5(15 * 30 / 100)
    Total 90 33.5
    Sub Sub Phase 1 % = 33.5 / 90 = 37.22
    and so on....
    Help me please and thanks.

    Apple has provided a tutorial that you can run through here:
    http://developer.apple.com/cocoa/coredatatutorial/index.html
    I have found their tutorials a great starting place for getting a simplified introduction to the new technologies.
    If you're still having trouble modeling your data after you read that, let us know.
    15.2" MacBook Pro Core 2 Duo 2.33GHz   Mac OS X (10.4.8)   WAY faster than my PowerBook G4

  • How to print this date format: eg. 14-Aug-2002 01:26:36 PM?

    Can anyone tell me exactly how to print this format?

    This is how we can produce the output you specified.
    import java.util.*;
    import java.text.*;
    //14-Aug-2002 01:26:36 PM?
    class Test
         public static void main(String args[])
              //Date b=new Date();
              //System.out.println(b.toString());
              // Format the current time.
              SimpleDateFormat formatter = new SimpleDateFormat ("dd-MMM-yyyy ' ' hh:mm:ss a");
              Date currentTime_1 = new Date();
              String dateString = formatter.format(currentTime_1);
              System.out.println(dateString);
    }//end of Test.

  • How to model hierarchical data?

    I need a way to model hierarchical data. I have tried using an object so far, and it hasn't worked. Here is the code for the class I made: http://home.iprimus.com.au/deeps/StatsGroupClass.java. As you can see, there are 4 fields: 1 to store the name of the "group", 2 integer data fields, and 1 Vector field to store all descendants. Unfortunately, this this not seem to be working as the Vector get(int index) method returns an Object. This is the error I get:
    Test.java:23: cannot resolve symbol
    symbol  : method getGroupName  ()
    location: class java.lang.Object
          echo("Primary Structure with index 0: " + data.get(0).getGroupName());
                                                            ^
    1 error I figure I can't use the approach I have been using because of this.
    Can anyone help me out?

    Test.java:23: cannot resolve symbolsymbol  : method getGroupName  ()location: class java.lang.Object      echo("Primary Structure with index 0: " + data.get(0).getGroupName());                                                        ^1 errorYou need to cast the return value from get(0):
    ((YourFunkyClass)data.get(0)).getGroupName();Be aware that you're opening yourself up to the possibility of a runtime ClassCastException. You could consider using generics if you can guarantee that the data Vector will contain only instances of YouFunkyClass.
    Hope this helps

  • How to solve this Data Configuration issue with error message ORA: 01017

    Bad public user name or password. ORA-01017: invalid username/password; logon denied
    How to solve this?

    I'm using JCreator jdk1.5.0_7.But i don't know how
    to use command prompt. When i execute my program, the
    command prompt showed
    Exception in thread "main"
    java.lang.NoClassDefFoundError: StringManipulation
    Press any key to continue...So you managed to compile your code since now you are running it. This error means that the class StringManipulation was not found. Usually an indicator that your classpath is incorrect.
    What did you do to generate this error? That is, how did you execute your program?
    [edit] if you did not compile your code then there is no class file StringManipulation.class and this error will appear.

  • How to get this date range

    Respecetd guru's,
    i have task to represent this date range start date to end date in every month.
    it show like this..
    01-sep-2009 to 30-sep-2009
    so on...
    plez help me.

    may be you are looking for this
    SQL> SELECT        TO_CHAR (TRUNC (ADD_MONTHS (SYSDATE, LEVEL), 'mm'),
      2                         'dd-mon-yyyy'
      3                        )
      4             || ' to '
      5             || TO_CHAR (LAST_DAY (ADD_MONTHS (SYSDATE, LEVEL)), 'dd-mon-yyyy')
      6                                                                             dt
      7        FROM DUAL
      8  CONNECT BY LEVEL <= 4;   -- change the range here instead of 4 to get a long range
    DT
    01-oct-2009 to 31-oct-2009
    01-nov-2009 to 30-nov-2009
    01-dec-2009 to 31-dec-2009
    01-jan-2010 to 31-jan-2010to get starting from 01-sep-2009
    use like this
    SQL> SELECT        TO_CHAR (TRUNC (ADD_MONTHS (SYSDATE, LEVEL-1), 'mm'),
      2                         'dd-mon-yyyy'
      3                        )
      4             || ' to '
      5             || TO_CHAR (LAST_DAY (ADD_MONTHS (SYSDATE, LEVEL-1)), 'dd-mon-yyyy')
      6                                                                             dt
      7        FROM DUAL
      8  CONNECT BY LEVEL <= 4;
    DT
    01-sep-2009 to 30-sep-2009
    01-oct-2009 to 31-oct-2009
    01-nov-2009 to 30-nov-2009
    01-dec-2009 to 31-dec-2009Edited by: Qwerty on Sep 8, 2009 8:51 PM

  • How i achive this data by writing exact query ?

    Dear Exparts,
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    "CORE     10.2.0.3.0     Production"
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - ProductionI have a table Name TB and Column A and B with the following data.
    A       B
    10     02-AUG-2012
    10     04-AUG-2012
    10     01-SEP-2012
    10     10-AUG-2012
    11     04-AUG-2012
    11     01-SEP-2012
    11     01-AUG-2012
    10     12-AUG-2012
    10     15-JUL-2012I need data like
    A                      B
    10            10-AUG-2012
    10            12-AUG-2012
    10            01-SEP-2012
    11            01-SEP-2012How we get this data ?
    We have to count column B group by Column A. then devided the count_value by 2 and trunc it and base on the result out put will come. the data are the maximum data.
    Like when we count group A result will be
    A            B
    10           3
    11           1base on above result my desire outpul will come...
    Here is the script
    CREATE TABLE TB
        "A" VARCHAR2(20 BYTE),
        "B" DATE
    Insert into TB (A,B) values ('10',to_date('02-AUG-2012','DD-MON-RRRR'));
    Insert into TB (A,B) values ('10',to_date('04-AUG-2012','DD-MON-RRRR'));
    Insert into TB (A,B) values ('10',to_date('01-SEP-2012','DD-MON-RRRR'));
    Insert into TB (A,B) values ('10',to_date('10-AUG-2012','DD-MON-RRRR'));
    Insert into TB (A,B) values ('11',to_date('04-AUG-2012','DD-MON-RRRR'));
    Insert into TB (A,B) values ('11',to_date('01-SEP-2012','DD-MON-RRRR'));
    Insert into TB (A,B) values ('11',to_date('01-AUG-2012','DD-MON-RRRR'));
    Insert into TB (A,B) values ('10',to_date('12-AUG-2012','DD-MON-RRRR'));
    Insert into TB (A,B) values ('10',to_date('15-JUL-2012','DD-MON-RRRR'));Thanks in advance...
    Ask2Learn
    Edited by: Asked to Learn on Sep 1, 2012 7:55 AM
    Edited by: Asked to Learn on Sep 1, 2012 8:38 AM (CHANGE DATA TYPE) SORRY

    this ?
    with t as
    select a,b,round(count(*) over(partition by a)/2) cnt,row_number() over(order by null) rn from tb
    ),t1 as
    select a.*,row_number() over(order by null) rn from tb a
    select t1.a,t1.b from t,t1 where t1.rn=t.rn and  t1.b>t.cnt order by a;
    A                    B                     
    10                   4                     
    10                   6                     
    10                   5                     
    11                   3                     
    4 rows selected
    Or
    with t as
    select a,b,round(count(*) over(partition by a)/2) cnt from tb
    select a,b from t where cnt<b;

  • How To solve this date issue

    Hello frenz,
    I have date in xml file as 2010-11-20T00:00:00.000+04:00
    but when I give this in the template as <?format-date:TRUNC_STH.TRAN_DATETIME_;'dd-MON-yyyy'?>)
    I get this date as 10-NOV-2010 but not 11-NOV-2010
    what's wrong pls tell me... has it got anything to do with the GMT

    Do have a look at the blog http://blogs.oracle.com/xmlpublisher/2009/06/how_to_keep_your_dates_from_go.html

  • How to Model this?

    Hello experts,
    Need help modelling the below data into Cubes:
    Sales Extractor:
    Has 30 fields including:
    Sales Doc: Sales Order Item: Config no.: Plant:  Material:  Customer Group: etc
    85252            10 1                4525           0001   Engine     10
    Options Extractor:
    Sales Doc:  Sales Order:  Item Config No.:  Characteristic Name:  Char Value:
    85252         10                 14525                Alternator                   ALT
    85252         10                 14525                Alternator                   ALT02
    85252         10                 14525                 Valve                         3
    (there maybe up to 100 characteristics for each Sales Doc)
    I have each extractor going into an ODS.
    Now I am not sure what to do next?
    For example I would want to run a report to see what Characteristics where sold to which customer group, so I need to bring both the ODS's together and then combine with a Cube (for Territory management from CRM).
    Do you have any ideas how I could design this
    Any help is much appreciated
    Many Thanks
    Helen

    Hi there,
    Thanks for your responses but I am still trying to get my head around how I would bring both extractors together
    These are the extractors:
    Sales Extractor
    Has 30 fields including:
    Sales Doc: Sales Order Item: Config no.: Plant: Material: Customer Group: etc
    85252 10 1 4525 0001 Engine 10
    Options Extractor:
    Sales Doc: Sales Order: Item Config No.: Characteristic Name: Char Value:
    85252 10 14525 Alternator ALT
    85252 10 14525 Alternator ALT02
    85252 10 14525 Valve 3
    Want to bring both together so that I can see the sales details per option
    eg  How many ALT's are sold in Plant 0001?
    At the moment both are coming into ODS?  do I build another ODS? use Infoset?etc
    Many Thanks for looking at this, really appreciate any advise
    Helen

  • How to get this data in CR

    not sure if it can be done in the Crystal report, but still want a help
    i have one column could show once or multiple times, and i need to count how many records show once, and how many records show multiple time, for example
    Column1  Column2
    win          xx1
    win          xx2
    win          xx3
    win          xx3
    win          xx4
    win          xx4
    win          xx4
    win          xx5
    if column2 record show once, it is stand alone server, if column2 record show multiple time, it is virtual server, so i want to show
    stand alone server    3
    virtual server             2
    is there a way to get this done in CR?
    thanks

    So you need to show the counts by type at the end of your report, not in the middle of reading the data, correct?
    Here's what I would do:
    1. Create a subreport and place it in your report footer.  You'll use essentially the same query in the subreport as you do in the main report and if you have any parameters in the main report, use them to link to the subreport.
    2.  Group the sub report by column 1.
    3.  Create two formulas that look something like this:
    {@StandAlone}
    If (PreviousIsNull({table.column2}) or {table.column2} <> previous({table.column2})) and (nextIsNull({table.column2}) or {table.column2} <> next({table.column2})) then 1 else 0
    {@Virtual}
    If {table.column2} = next({table.column2}) and ( PreviousIsNull({table.column2}) or {table.column2} <> previous({table.column2}) ) then 1 else 2
    4.  Sum each of these formulas at the column1 group level to get your counts.
    -Dell

  • How to get this data : QAPO-PRPLATZ

    Dear All ,
    I have a Lot Number , all the him characteristic and i need to take only this information :
    QAPO-PRPLATZ (I think that is the operation name)
    How can i get the data ?
    Wich is the correct way ?
    Thanks

    Dear Ramudu  ,
    My scenario is this :
    I have to change a SAP Program that extracts all the lots created/edited since an input date and all the lots characteristics that was changed/inserted since an input date . . .
    The last version of this program is using the Logical DB now i have to create a new version
    that extract the data by a query that works on edit/creation date . . .
    If i have understood i have to launch for each lots the function module : PM_ORDER_GET_HIERARCHY .
    May the performance falls in this way ?
    There are any other way to find QAPO data ?
    Thank you very much.

  • How to get this data in the WebI

    Hi There
    i have a WebI report, the data looks like this
    userName    Type
    Mike              DT
    Mike              NB
    Susan           DT
    Colleen          DT
    Colleen          NB
    i only need to pick up Mike and Colleen, cause only they have both DT and NB, how can i get the data like this?
    thanks

    Create a variable as below:
    [ctgt1type]=Count([type]) ForEach([username]) In Report>1
    Then create a filter with this condition:
    [ctgt1type]=1
    This might work. I tried this with the Islands marketing universe selecting customer and country to display only customers with multiple countries. But your original soulton is more elegant and with report level filters more development and maintenance efforts are required
    Edited by: Uvee on Nov 2, 2011 2:24 PM

Maybe you are looking for

  • Did not find error in message but message is in error

    Hi dears, i got a synchronous message in error.and i checked that in SXMB_MONI.Where its original message is recorded and its  response message is in error category of 'Request Message Mapping' .with no error id. i want to find exact error in its Tra

  • 1.2 firmware, where are you Apple?

    Apple I am sure that you are more that aware of the problems of firmeware rev. 1.2. Are these problems that those of us are having fixable? Or is this a hardware problem and you are trying to wait until the one year warranty is gone to inform us? To

  • Connect iPad directly to MBP using a computer to computer network

    Hi I'm awful at networking, so please excuse my ignorance. I am going away from home soon and there is no wireless network available, no router etc. I want to be able to connect my ipad to my MBP wirelessly so that I can use home sharing etc. How do

  • Search by a Name using Wildcard

    When searching with Step* the customer Stephen will be found.  But, when searching with St* the customer Stephen will be not found.  Why?  What is the solution? and reason?  Can any body pls......

  • Can AlphaComposite merge colors as lights, not pigments?

    There ware two ways to composite colors in overlapping regions: @: additively, as lights -- the more colors are added, the brighter the result @: subtractively, as paints -- the more colors are added, the darker the result In additive composition, re