Challenge with Pivoting data

Hi Everyone,
I have an interesting challenge which involves extracting data from two related databases, and pivoting part of the data from the second.
Where I work we use SAP Business One (ERP) in concert with Accellos (WMS). Within our Warehouses we store items in many bin locations. Bin locations; items in those locations, along with quantities, etc are stored in the Accellos database. Master data related
to the items themselves, such as the item cost, preferred supplier, etc is stored in SAP Business One.
Whilst I have been able to create reports which successfully bridge both SAP & Accellos, such as that shown below, I have not been able to present the data output in an ideal format.
As can be seen above given a single item code (e.g.: DR1124) there are many bin labels (and corresponding quantities) returned.
I would like to show the bin labels 'horizontally' in the fashion illustrated below -
I believe that using a Pivot is pivotal (excuse the pun!) to success in my endeavour, and due to this I have studied up on Pivots, both the Static type (which I am now comfortable with) and the Dynamic type (which I am still getting 'my head around').
However there are a couple of challenges related to my specific pivot.
The maximum number of Bins (and correspondingly Bin Labels) per Item change
There are over 10K Bin Labels
I have written a basic Dynamic Pivot which shows all Bin Labels horizontally, like so...
DECLARE @SQL nvarchar(max), @Columns nvarchar(max)
SELECT @Columns =
COALESCE(@Columns + ', ', '') + QUOTENAME(BINLABEL)
FROM
SELECT DISTINCT
BINLABEL
FROM A1Warehouse..BINLOCAT
) AS B
ORDER BY B.BINLABEL
SET @SQL = '
WITH PivotData AS
SELECT
BINLABEL
, PRODUCT
, QUANTITY
FROM A1Warehouse..BINLOCAT
SELECT
PRODUCT,
'+ @Columns +'
FROM PivotData
PIVOT
SUM(QUANTITY)
FOR BINLABEL
IN('+ @Columns +')
) AS PivotResult'
EXEC(@SQL)
The above technique gives me over 10K columns because there are that many Bin Labels in total.
It occurred to me that I would need to count the maximum number of Bin Labels for the Item that had the most Bin Labels, and that this number would then need to be used to set the maximum number of columns.
DECLARE @maxBins int
DECLARE @loopCount int = 1
SET @maxBins = (SELECT MAX([# of Bins]) AS 'Max Bins'
FROM
SELECT
COUNT(BINLABEL) '# of Bins'
FROM A1Warehouse..BINLOCAT
GROUP BY PRODUCT
) AS T0)
PRINT @maxBins
At this point in time one item occupies a total of 26 bin labels / locations. Every other item occupies less than 26 bin labels / locations, so I now know that I need to number my vertical columns as 'Bin 1', 'Bin 2', 'Bin 3', 'Bin...', 'Bin 26'.
This is where the fun starts, I don't exactly need a Dynamic Pivot, but neither is a Static Pivot up to the task (at least not as best I can tell).
Here is the Static Pivot query that I have written -
DECLARE @fromDate DATE = DATEADD(YY, -1, GETDATE())
DECLARE @toDate DATE = GETDATE()
DECLARE @maxBins int
DECLARE @loopCount int = 1
SET @maxBins = (SELECT MAX([# of Bins]) AS 'Max Bins'
FROM
SELECT
COUNT(BINLABEL) '# of Bins'
FROM A1Warehouse..BINLOCAT
GROUP BY PRODUCT
) AS T0)
PRINT @maxBins
SELECT *
FROM
SELECT
Tx.[Item Code]
, Tx.Description
, SUM(Tx.[Sales (last 12 Months)]) AS 'Sales (last 12 Months)'
, ISNULL(Tx.[Supplier Code], '') AS 'Supplier Code'
, ISNULL(Tx.[Supplier Name], '') AS 'Supplier Name'
, Tx.OnOrder
, Tx.IsCommited
, Tx.OnHand
, ISNULL(Tx.BINLABEL, '') AS 'Binlabel'
, ISNULL(CAST(Tx.QUANTITY AS nvarchar), '') AS 'Quantity'
FROM
SELECT
T0.ItemCode AS 'Item Code'
, T0.Dscription AS 'Description'
, SUM(T0.Quantity) AS 'Sales (last 12 Months)'
, T3.CardCode AS 'Supplier Code'
, T3.CardName AS 'Supplier Name'
, T2.OnOrder
, T2.IsCommited
, T2.OnHand
, T4.BINLABEL
, T4.QUANTITY
FROM INV1 T0
INNER JOIN OINV T1 ON T1.DocEntry = T0.DocEntry AND T1.CANCELED = 'N'
INNER JOIN OITM T2 ON T2.ItemCode = T0.ItemCode
LEFT JOIN OCRD T3 ON T3.CardCode = T2.CardCode
LEFT JOIN A1Warehouse..BINLOCAT T4 ON T4.PRODUCT = T0.ItemCode collate SQL_Latin1_General_CP850_CI_AS
WHERE T1.DocDate >= @fromDate AND T1.DocDate <= @toDate
GROUP BY T0.ItemCode, T0.Dscription, T3.CardCode, T3.CardName, T2.OnOrder, T2.IsCommited, T2.OnHand, T4.BINLABEL, T4.QUANTITY
UNION ALL
SELECT
T0.ItemCode AS 'Item Code'
, T0.Dscription AS 'Description'
, -SUM(T0.Quantity) AS 'Sales (last 12 Months)'
, T3.CardCode AS 'Supplier Code'
, T3.CardName AS 'Supplier Name'
, T2.OnOrder
, T2.IsCommited
, T2.OnHand
, T4.BINLABEL
, T4.QUANTITY
FROM RIN1 T0
INNER JOIN ORIN T1 ON T1.DocEntry = T0.DocEntry
INNER JOIN OITM T2 ON T2.ItemCode = T0.ItemCode
LEFT JOIN OCRD T3 ON T3.CardCode = T2.CardCode
LEFT JOIN A1Warehouse..BINLOCAT T4 ON T4.PRODUCT = T0.ItemCode collate SQL_Latin1_General_CP850_CI_AS
WHERE T1.DocDate >= @fromDate AND T1.DocDate <= @toDate
GROUP BY T0.ItemCode, T0.Dscription, T3.CardCode, T3.CardName, T2.OnOrder, T2.IsCommited, T2.OnHand, T4.BINLABEL, T4.QUANTITY
)Tx
GROUP BY Tx.[Item Code], Tx.Description, Tx.[Supplier Code], Tx.[Supplier Code], Tx.[Supplier Name], Tx.OnOrder, Tx.IsCommited, Tx.OnHand, Tx.BINLABEL, Tx.QUANTITY
)Ty
PIVOT
MAX(Ty.Quantity)
FOR Ty.Binlabel IN ([0], [1], [2])
)Tz
Here is a screen shot of the results that I see -
I understand why there are NULLs in my 0, 1, and 2 columns...there simply aren't Bin Labels called 0, 1 or 2!
My challenge is that I do not know how to proceed from here. Firstly how do I call each of the pivoted columns 'Bin 1', 'Bin 2', 'Bin...', 'Bin 26' when the actual Bin Labels are over 10 thousand different possible character sets, e.g.: #0005540, K1C0102, etc,
etc, etc...
I have considered the possibility that a WHILE loop may be able to serve in populating the column names...
DECLARE @maxBins int
DECLARE @loopCount int = 1
SET @maxBins = (SELECT MAX([# of Bins]) AS 'Max Bins'
FROM
SELECT
COUNT(BINLABEL) '# of Bins'
FROM A1Warehouse..BINLOCAT
GROUP BY PRODUCT
) AS T0)
PRINT @maxBins
WHILE @loopCount <= @maxBins
BEGIN
PRINT @loopCount
SET @loopCount = @loopCount +1
END
...of course the query above has no practical application at this stage, but I thought that it may be useful
from a 'logic' point of view.
I have tried to insert a WHILE clause into various locations within the Static Pivot query that I wrote, however in each instance there were errors produced by SSMS.
If anybody can suggest a way to solve my data pivoting challenge it will be much appreciated.
Kind Regards,
David

How you can 'assign' multiple values to the @SQL variable (if that is indeed what is happening)
What 'FOR XML PATH('') actually does
Dynamic SQL in general...
if you could share some insights into how I can go about removing the NULLs it will be greatly appreciated.
The FOR XML PATH('') method is one of several ways to concatenate the values from several rows into one column of one row.  There are other ways, but I believe the most commonly used one today (and certainly the one I always use) is the FOR XML method. 
A good link for understanding the FOR XML method is
http://bradsruminations.blogspot.com/2009/10/making-list-and-checking-it-twice.html.
If you are not used to dynamic SQL, there is an excellent discussion at http://www.sommarskog.se/dynamic_sql.html.  If you are not used to dynamic SQL, you definitely want to review the SQL Injection topic on that page before making extensive use of
dynamic SQL. 
You can get rid of the NULLs, but only by converting the NULLs into a value.  You can use the IsNull() function or as diadmin noted the Coalesce() function to do this.  There is, however, the question of what value do you want.  Of course
the obvious choice for converting varchar values (like BinLabel) is the empty string ('').  But for numeric values (like BinQty) you need to either output a number (like 0.000000) or you need to convert the numbers into a character type and then you could
use the empty string.  Of course doing this makes this already complex piece of SQL more complex, but it certainly can be done.  An example
Create Table Foo(ItemCode varchar(6), ItemDescription varchar(50), OrderQty decimal(12,6), BinLabel varchar(7), BinQty decimal(12,6));
Insert Foo(ItemCode, ItemDescription, OrderQty, BinLabel, BinQty) Values
('DR1124', 'D6 Series 24 OD 3/8 1 Neck', 50, 'B1A1904', 9),
('DR1124', 'D6 Series 24 OD 3/8 1 Neck', 50, 'M1D0703', 66),
('DR1124', 'D6 Series 24 OD 3/8 1 Neck', 50, 'S1K0603', 24),
('H21', 'Rubber Mallot', 75, 'X1X0712', 100),
('H21', 'Rubber Mallot', 75, 'T3B4567', 92);
Declare @SQL nvarchar(max);
;With cteRN As
(Select ItemCode, ItemDescription, BinLabel, BinQty,
Row_Number() Over(Partition By ItemCode Order By BinLabel) As rn
From Foo)
Select @SQL = (Select Cast(N'' As nvarchar(max)) + N', IsNull(Max(Case When rn = ' + Cast(rn As nvarchar(5)) + N' Then BinLabel End), '''') As BinLabel' + Cast(rn As nvarchar(5))
+ N', IsNull(Cast(Max(Case When rn = ' + Cast(rn As nvarchar(5)) + N' Then BinQty End) As varchar(19)), '''') As BinQty' + Cast(rn As nvarchar(5))
From (Select Distinct rn From cteRN) x
Order By rn
For XML Path(''))
Select @SQL = Stuff(@SQL, 1, 2, '');
--Select @SQL
Select @SQL = N'Select ItemCode, Max(ItemDescription) As ItemDescription, Max(OrderQty) As OrderQty,' + @SQL + N' From (Select ItemCode, ItemDescription, OrderQty, BinLabel, BinQty,
Row_Number() Over(Partition By ItemCode Order By BinLabel) As rn
From Foo) As x Group By ItemCode'
--select @SQL
Exec(@SQL);
-- Cleanup
go
Drop Table Foo;
Tom

Similar Messages

  • Please Help! with a data merge

    Iam trying to do a data merge for my client in Indesign this is a new challenge to me and have gone through many a tutorial and uTube video but still cant get it to work properly.
    Iam hoping that someone can give me some advise.
    I have 11 different images (product Labels) that need personalisation with a data merge. I have attached the data merge file preview and the txt file (tab delimited text. txt)
    As you can see the data merge text, seems to overflow into all the other boxes. (The blank boxes hold white text) and the images dont appear at all. Any suggestions would be really appreciated.
    Thanks

    So you did press the preview button...
    First thing I see though, is the image tag is in a text frame, not an image frame, or at least that's the way it looks in the screen cap, but it does appear correct in the prvious version, so it might just be the way the frames are displayed.
    But I suspect, too, that the file is now damaged. The preview button is buggy, and once you've pressed it and then done a merge the odds that the file will ever work correctly are small. Best thing is to rebuild the template in a new file and merge without pressing preview (just trust it will work). Copy/paste from the old file seems to be OK to do this.

  • Problem with PIVOT statement and ORA-56901

    Hi,
    I am having a problem with PIVOT in Oracle.
    I have a view in an oracle 11g database
    that returns me data in the format:- (... indicates left out text)
    DefinitionID ... AttributeValue FieldID
    ============ ============== =======
    ... 3000 X30a9...
    ... JohnN X4674...
    I am then trying to use a PIVOT statement to hopefully give me data
    in the format
    COLUMN1 COLUMN2
    ======= =======
    JohnN 3000
    The PIVOT statement I am trying is
    SELECT X4674... AS Column1,
    X30A9... AS COLUMN2
    FROM (SELECT instanceid, definitionid, attributevalue, FIELDID
    FROM PI_ENTITY_INSTANCE_VIEW) up PIVOT (MAX(ATTRIBUTEVALUE)
    FOR FIELDID IN (X4674...,X30A9... ) )
    where definitionid = hextoraw('7353C67A56C74B5A8234CD16064399E8')
    I have used a very similar VIEW and PIVOT statement for sql server
    (with necessary changes for Oracle applied) and the
    data returns in SQL Server as expected.
    Unfortunately I am getting the Oracle error
    ORA-56901: non-constant expression is not allowed for pivot|unpivot values
    Is there anyway to get a PIVOT working on Oracle where I use the
    fieldid's like I do above or is there some other way to supply the vales to the
    IN clause to overcome this error?
    Thank you for any help you can provide
    John Nugent

    Hi, John,
    Welcome to the forum!
    X4674, X30A9 and os on are the literal values that you're looking for, right?
    In Oracle, string literals need to be enclosed in single-quotes, like this:
    FOR FIELDID IN ('X4674', 'X30A9') You might find it more convenient to assign column aliases in the PIVOT clause, like this:
    PIVOT   (     MAX (attributevalue)
         FOR     fieldid       IN ( 'X4674'     AS column1
                        , 'X30A9'     AS column2
         ) Remember that anything inside quotes is case-sensitive, so 'X30A9' is not equal to 'X30a9'. Use UPPER (or LOWER) to do case-insensitive string comparisons.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    If you can use commonly available tables (such as those in the scott or hr schemas) to show your problem, then you don't have to post any sample data; just the results and explanation.
    Always say which version of Oracle you're using. You did say you were using Oracle 11g, but there's no 11f or 11h, and sometimes the difference between, say 11.1 and 11.2 can be significant. Why not say exactly what you're using, e.g. 11.1.0.7.0?
    You'll get better answers faster if you always supply this information whenever you post a question.
    Edited by: Frank Kulash on Sep 22, 2011 2:09 PM
    Added allliterative alias alternative
    Edited by: Frank Kulash on Sep 22, 2011 4:04 PM

  • Java API for working with Pivot Tables...?

    Hi,
    I want to create/modify an existing pivot table in an excel sheet. Is there any open source available to work on pivot tables.
    I have seen few articles mentioning that POI supports updation of data, though the apache site says that it does not support working with pivot tables. I am able to copy an existing excel template with pivot table to a new excel using poi but am stuck with updating....
    Thanx,
    Praveen.

    Hi,
    The JExcelAPI does not support working with pivot tables... I am still in search of an open source to work with pivot tables....
    btw, we are able to update an existing pivot table using apache poi. But we need to change the data range of the pivot table during run time... Am stuck with this... Has anyone come across any open source to work with pivots???
    Regards...

  • Materialized view with xmltype data type

    Hello to all,
    I have a challenge with my 10g r2 database. I need to make a materialized view from a table in this format:
    Name Null? Type
    RECID NOT NULL VARCHAR2(200)
    XMLRECORD XMLTYPE
    ,my problem is that (as i read from docs) i cant make the view refreshable on commit and also i cant refresh the mv in fast mode ( i dont need to refresh mv complete - takes too long).
    Do you have a hint for this?
    Thank you in advance.
    Daniel

    hi,
    I cant upgrade to 11g.Also i cant change the table structure.
    Here is a sample of xmltype field content:
    RECID      XMLRECORD
    D00009999      <row id='D100009999'><c2>10000</c2><c3>xxxxx</c3><c5>xxxx..
    And i need to extract in the mv the data from c2, c3 and so on.
    Still waiting for a hint.
    Thank you.

  • Trouble writing Query for Pivoting data from a table

    I am having a little trouble writing a query for converting the below table data into a pivot data. I am trying to write a query for which if I give a single valid report_week date as input it should give me the data for that week and also provide two extra columns, one which gives the data of last week for the same countries and the second column which gives the difference of numbers in both the columns(i.e. COUNT - COUNT_LAST_WEEK).
    REPORT_WEEK     DIVISION     COUNT
    9/26/2009     country1     81
    9/26/2009     country2     97
    9/26/2009     country3     12
    9/26/2009     country4     26
    9/26/2009     country5     101
    10/3/2009     country1     85
    10/3/2009     country2     98
    10/3/2009     country3     10
    10/3/2009     country4     24
    10/3/2009     country5     101
    10/10/2009     country1     84
    10/10/2009     country2     98
    10/10/2009     country3     10
    10/10/2009     country4     25
    10/10/2009     country5     102
    For example, if I give input as 10/10/2009, the output should be as give below.
    REPORT_WEEK     DIVISION     COUNT     COUNT_LAST_WEEK     DIFFERENCE
    10/10/2009     country1     84     85     -1
    10/10/2009     country2     98     98     0
    10/10/2009     country3     10     10     0
    10/10/2009     country4     25     24     1
    10/10/2009     country5     102     101     1
    For example, if I give input as 10/3/2009, the output should be as give below.
    REPORT_WEEK     DIVISION     COUNT     COUNT_LAST_WEEK     DIFFERENCE
    10/3/2009     country1     85     81     4
    10/3/2009     country2     98     97     1
    10/3/2009     country3     10     12     -2
    10/3/2009     country4     24     26     -2
    10/3/2009     country5     101     101     0
    Can anyone please shed some light on Query building for the above scenarios.
    Thank you
    SKP
    Edited by: user11343284 on Oct 10, 2009 7:53 AM
    Edited by: user11343284 on Oct 10, 2009 8:28 AM

    I assume there is no gap in report weeks. If so:
    SQL> variable report_week varchar2(10)
    SQL> exec :report_week := '10/10/2009'
    PL/SQL procedure successfully completed.
    with t as (
               select to_date('9/26/2009','mm/dd/yyyy') report_week,'country1' division,81 cnt from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country2',97 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country3',12 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country4',26 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country5',101 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country1',85 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country2',98 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country3',10 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country4',24 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country5',101 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country1',84 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country2',98 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country3',10 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country4',25 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country5',102 from dual
    select  max(report_week) report_week,
            division,
            max(cnt) keep(dense_rank last order by report_week) cnt_this_week,
            max(cnt) keep(dense_rank first order by report_week) cnt_last_week,
            max(cnt) keep(dense_rank last order by report_week) - max(cnt) keep(dense_rank first order by report_week) difference
      from  t
      where report_week in (to_date(:report_week,'mm/dd/yyyy'),to_date(:report_week,'mm/dd/yyyy') - 7)
      group by division
      order by division
    REPORT_WE DIVISION CNT_THIS_WEEK CNT_LAST_WEEK DIFFERENCE
    10-OCT-09 country1            84            85         -1
    10-OCT-09 country2            98            98          0
    10-OCT-09 country3            10            10          0
    10-OCT-09 country4            25            24          1
    10-OCT-09 country5           102           101          1
    SQL> exec :report_week := '10/3/2009'
    PL/SQL procedure successfully completed.
    SQL> /
    REPORT_WE DIVISION CNT_THIS_WEEK CNT_LAST_WEEK DIFFERENCE
    03-OCT-09 country1            85            81          4
    03-OCT-09 country2            98            97          1
    03-OCT-09 country3            10            12         -2
    03-OCT-09 country4            24            26         -2
    03-OCT-09 country5           101           101          0
    SQL> SY.

  • Pivoting date data in Diadem - summarising data by grouping

    Hi,
    Is there a way to summarise date data in Diadem?
    For example, if I have a file with the following headings:
    Date/time, on/off, duration
    The Date/time column is recordrded in date, hours and seconds,
    the on/off is either 1 or 0
    duration is the difference in time values when on/off is 1.
    Is there a way to summarise the date data by day or possibly by month? (The corresponding numbers in 'duration' would need to be assigned to the appropriate day or month)?
    The equivalent calculation tool would be a pivot table in Excel.
    Look foward to a response.

    Hi Brad,
    Thank you for your prompt response.
    I have attached a file in the code section with some data. (Apologies for this, but the NI website said the content did not match the filetype). (I will try and get this right and send the attachement as an excel file. DIADEM should be able to read in the text file).
    The columns are as follows: Event, Date,Time,Duration On,State.
    (please note 1) that in the 'event' column there are 5 boilers - good for pivoting once grouped per boiler,
                         2) that 'State' is either a save or a bypass - also good for pivoting i.e. which days and boilers were in bypass, and which days and boilers were in save)
    I would like to be able to summarise the data as follows:
    Show a period(group by month or year) the sum of the Duration On, then display the result on a monthly histogram showing for example daily Duration On vs date.
    Then
                       on an annual histogram showing for example monthly Duration On vs month.
    As the last part of the exercise, how can I break out doing the 2 steps about for each of the 5 seperate boilers and show when each of the boilers were in a save or a bypass?
    (Is a pivot table in excel required or can all the data processing be done in DIADEM?)
    I appreciate your assistance in resolving this issue.
    Sincerely
    HotCold
    Attachments:
    Heathrow.txt ‏442 KB

  • PowerPivot Dates with no Data

    I've got a classic "fact" table with Membership data linked to a "date" dimension table.  The fact table stores membership data at each month end date.  My Members Added measure works as expected, but Members Added YTD repeats
    for every date in the Dim_Date table.  I wasn't expecting that.  I only want to show the dates for which there is data.
    Members Added:  =CALCULATE(SUM(Fact_MemberWalk[MemberCount]),Fact_MemberWalk[TranType]="New Member")
    Members Added YTD: CALCULATE([Members Added],DATESYTD(Dim_Date[DateKey]))
    Picture of Problem:
    Kirk P.

    Hi Kirk,
    According to your description, this issue is more related to Power Pivot. The Power Pivot forum is a better place for Power Pivot issue, we will move it there for you.
    Regards
    Starain
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Pivoting data

    Hi, I'm hoping someone can point me in the right direction...
    I need to create a report that pivots data, however I'm struggling to get the resultset I'm looking for. I need to display the data below:
    MANAGER     U_ID     A B C      
    1703      1703      3     3     1     
    1703      1702     1     1     1     
    1703      1701     0     2     0     
    like so: MANAGER U_ID
    sum of A 4 3
    sum of B 6 1
    sum of C 2 1
    Hope that makes sense. Any help is really appreciated.
    Thanks

    Hi,
    Andyindo wrote:
    Hi, I'm hoping someone can point me in the right direction...
    I need to create a report that pivots data, however I'm struggling to get the resultset I'm looking for. I need to display the data below:
    MANAGER     U_ID     A B C      
    1703      1703      3     3     1     
    1703      1702     1     1     1     
    1703      1701     0     2     0     
    like so: MANAGER U_ID
    sum of A 4 3
    sum of B 6 1
    sum of C 2 1You may have noticed that this site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (such as query results) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    Hope that makes sense. Any help is really appreciated.It looks like you want to pivot and unpivot in the same query.
    The following thread has an example of how to do that:
    Re: Help with PIVOT query (or advice on best way to do this)
    Whenever you have a question, post CREATE TABLE and INSERT statements for the sample data, and explain how you get the results you want from that data.  I can guess at what the next-to-last column of output is, but guessing isn't a very good way to solve problems, and might not be as accurate as what you know.  What does the last column of output mean?  How do you get those numbers, 3, 1 and 1?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Need help with Pivoting rows to columns

    Hi,
    I need help with pivoting rows to columns. I know there are other posts regarding this, but my requirement is more complex and harder. So, please give me a solution for this.
    There are two tables say Table 1 and Table 2.
    Table1
    name address email identifier
    x e g 1
    f s d 2
    h e n 3
    k l b 4
    Table2
    identifier TRno zno bzid
    1 T11 z11 b11
    1 T12 z12 b12
    1 T13 z13 b13
    2 T21 z21 b21
    2 T22 z22 b22
    As you can see the identifier is the column that we use to map the two tables. The output should be like below
    output
    name address email identifier TRno1 zno1 bzid1 TRno2 zno2 bzid2 TRno3 zno3 bzid3
    x e g 1 T11 z11 b11 T12 z12 b12 T13 z13 b13
    f s d 2 T21 z21 b21 t22 z22 b22
    Also we do not know exactly how many TRno's, zno's, etc each value in the identifier will have. There may be only 1 TRNO, zno and bzid, or there may be four.
    All the values must be in separate columns, and not be just comma delimitted. There are also other conditions that i have to add to restrict the data.
    So, can you please tell me what is should use to get the data in the required format? We are using Oracle 10g. Please let me know if u need any more information

    Something like this ?
    SCOTT@orcl> ed
    Wrote file afiedt.buf
      1  select a.name,
      2  a.address,
      3  a.email,
      4  b.* from (
      5  select distinct identifier
      6  ,max(trno1) trno1
      7  ,max(zno1) zno1
      8  ,max(bzid1) bzid1
      9  ,max(trno2) trno2
    10  ,max(zno2) zno2
    11  ,max(bzid2) bzid2
    12  ,max(trno3) trno3
    13  ,max(zno3) zno3
    14  ,max(bzid3) bzid3
    15  ,max(trno4) trno4
    16  ,max(zno4) zno4
    17  ,max(bzid4) bzid4
    18  from (select identifier
    19  ,decode(rn,1,trno,null) trno1
    20  ,decode(rn,1,zno,null) zno1
    21  ,decode(rn,1,bzid,null) bzid1
    22  ,decode(rn,2,trno,null) trno2
    23  ,decode(rn,2,zno,null) zno2
    24  ,decode(rn,2,bzid,null) bzid2
    25  ,decode(rn,3,trno,null) trno3
    26  ,decode(rn,3,zno,null) zno3
    27  ,decode(rn,3,bzid,null) bzid3
    28  ,decode(rn,4,trno,null) trno4
    29  ,decode(rn,4,zno,null) zno4
    30  ,decode(rn,4,bzid,null) bzid4
    31  from (select identifier,
    32  trno,bzid,zno,
    33  dense_rank() over(partition by identifier order by trno,rownum) rn
    34  from table2)
    35  order by identifier)
    36  group by identifier) b,table1 a
    37* where a.identifier=b.identifier
    SCOTT@orcl> /
    NAME       ADDRESS    EMAIL      IDENTIFIER TRNO1      ZNO1       BZID1      TRNO2      ZNO2       BZID2      TRNO3      ZNO3       BZID3      TRNO4      ZNO4       BZID4
    x          e          g          1          T11        z11        b11        T12        z12        b12        T13        z13        b13
    f          s          d          2          T21        z21        b21        T22        z22        b22
    SCOTT@orcl> select * from table1;
    NAME       ADDRESS    EMAIL      IDENTIFIER
    x          e          g          1
    f          s          d          2
    h          e          n          3
    k          l          b          4
    SCOTT@orcl> select * from table2;
    IDENTIFIER TRNO       ZNO        BZID
    1          T11        z11        b11
    1          T12        z12        b12
    1          T13        z13        b13
    2          T21        z21        b21
    2          T22        z22        b22
    SCOTT@orcl>Regards
    Girish Sharma

  • Hide Series with no data

    Dear friends,
    please your help with this issue.
    I have 2D column chart with multi Series, is there any way to hide series without date.
    i.e.. series depends on parameter i want to hide the Series if I did not enter the Series parameter.
    I hope that was clear.
    thanks all

    Hi,
    As far as I know, the "Hide items with no data" of slicer works for the values category in the pivot table. If the values category in the pivot table is empty, the slicer will hide the rows. And the other situations (we do not put the data in values
    category), it'll not hide the rows. Because the rows are also the records of the data source. (It also applies to the table in Excel 2013)
    Thanks,
    George Zhao
    TechNet Community Support

  • Report doest get refreshed with updated data

    Hi All,
    I am facing a strange problem, where my report doest get refreshed with updated data when it’s called second time.
    1.     Screen1 – Preview option – Preview Screen
    2.     Preview Screen – Print option (Button) – Report generated and displayed in the IE Browser window with a dynamically generated PIN (Query written in WHEN-BUTTON-PRESSED trigger)
    3.     Screen2 is displayed in the backend
    4.     Screen2 – Cancel option – Screen1
    5.     Screen1 – Preview option – Preview Screen
    6.     Preview Screen – Print option (Button) – Report generated and displayed in the IE Browser window with a same PIN as in step2. Actually here the Query written in WHEN-BUTTON-PRESSED trigger generates a new PIN.
    7.     When checked in the backend this new PIN is updated, but the same is not displayed on the Report. That means to say that report is not refreshed. When I click on the refresh button in the IE Browser window explicitly, the report is refreshed and displays the PIN as found in the backend.
    What I expect is that the report should get refreshed automatically with a new PIN, when I choose Print option in Preview Screen.
    Can anybody help me in overcoming this challenge?
    Regards,
    SAM

    Hi All,
    What i did was i encoded the PIN and sent it as a paramter to call the report.
    In the report i decoded the PIN and printed it. This way my URL to call the report was always updated with the decoded PIN value and would refresh the page successfully, everytime its called.
    Regards,
    SAM

  • Problme with f1 99\02 challenge with Ti VTD8X 4200

    i have problme
    i can't play f1 99\02 challenge with windwos xp I\O and Ti VTD8X 2004 GF4
    when the installations finish it is supposed to check texture that'e doesn't happen on WinXp Proffesionl and it occured (F1 3Dsetup).
    in the time i can do it with windows 98 Se without problmes
    so any one can help me please
    thanks
    I have P4 2.4 Speed
    512 MB DDR Ram fre 333
    Asus Mainboard P4P8x
    And this problme face me in another little games

    put this in your reg
    Home > Windows > Appearance
    DirectDraw and Direct3D Settings (Windows 98/Me/2000/XP)
    These DirectX settings allow you to change some of the DirectDraw and Direct3D video acceleration parameters.
    Open your registry and find or create the key below.
    Create a new DWORD value for each optional item from the list below and set it to "1" to enable the setting or "0" to disable it.
    Open the [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Direct3D] key and change the value of DisableDP2 to "1" to disable Direct3D, or "0" to enable it.
    Open the [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Direct3D\Drivers] key and change the value of SoftwareOnly to "1" to use software emulation or "0" to disable it.
    Restart Windows for the change to take effect.
       HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectDraw  
    Registry Settings
    System Key: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectDraw]
    Data Type: REG_DWORD (DWORD Value)
    Value Data: (0 or 1)
    I can play all my older games with this in my reg and without it the games don't work,

  • Excel Workbook with Excel Data Model stored on SharePoint - daily refresh

    I'm not sure if this is exactly the right forum but I'm hoping that someone here can either answer or point me in the right direction.
    I have an Excel Workbook with an Excel Data Model.
    The Excel Data Model uses SQL to contact our data warehouse and pull through data into tables.
    We are storing the Workbook on a SharePoint site and viewing it using Excel Services.
    The data in our data warehouse is updated daily and so I would like to refresh the workbook daily and remove the option to refresh the data in the browser.
    Is this possible with a workbook that has an Excel Data Model (I've seen lots of posts that relate to workbooks with connections to tabular models).
    Thanks
    Paul

    Hi Paul,
    I have answered this issue in this thread that you posted in SQL Server PowerPivot for SharePoint forum, please see:
    http://social.msdn.microsoft.com/Forums/en-US/9627939c-e9f1-48ae-a6ed-0c238d8f2d69/excel-workbook-with-excel-data-model-stored-on-sharepoint-daily-refresh?forum=sqlkjpowerpointforsharepoint
    Furthermore, this issue is more related to PowerPivot for SharePoint. If you have any more questions about PowerPivot for SharePoint, I would sugget you open a new thread in the forum below for better support:
    http://social.msdn.microsoft.com/Forums/en-US/home?forum=sqlkjpowerpointforsharepoint
    Thanks for your understanding.
    Regards,
    Elvis Long
    TechNet Community Support

  • Help needed with missing data problem in CRVS2010

    We recently upgraded the reporting engine in our product to use Crystal Reports for Visual Studio 2010 (previously engine was CR9). Our quote report, which has numerous subreports and lots of conditional formatting, started losing data when a quote took more than a single page to be printed. We knew the SQL results included the data, but the report was not printing those lines at all or sometimes printing a partial line. In addition, the running total on the report would exclude the lines that were being missed on the next page. In one example submitted by a customer, 3 lines were skipped between pages.
    I think I have identified two potential issues that document the possibility of data not being included in the report.
    The first potential issue is an issue with the "suppress blank section" option being checked. This issue is supposedly fixed with ADAPT01483793, being released someday with service pack 2 for CRVS2010.
    The second potential issue is using shared variables. This issue is supposedly fixed with ADAPT01484308, also targeted for SP2.
    Our quote report does not explicitly use shared variables with any of the subreports, but it does have several subreports, each in its own section that has the "supress blank section" option checked. We have other reports that use this feature, as well, and they are not exhibiting the problem.
    One different thing about the quote report is that it has a section with multiple suppression options selected. The section has a conditional suppression formula, which controls whether the section is included at all within the report. The section also has the suppress blank section option selected. There are multiple fields within the report that are each conditionally suppressed. In theory, the section's suppress formula could evaluate to true, yet all of the fields within the section are suppressed (due to null values), and then the "suppress blank section" option would kick in.
    The missing data only seems to happen when the section is not being suppressed, and at least one of the fields is being included in the report. If I clear the "suppress blank section" check box, and change the section formula to also include the rules applied to the fields in the section, the missing data problem seems to be resolved.
    Is this related to ADAPT01483793? Will it be fixed in service pack 2?
    If more details are needed, I would be happy to provide a sample report with stored data.

    Hi Don,
    Have a look at the Record Selection formula in CR Designer ( stand alone ) and when exported to RPT format opening that report in the Designer also. 
    There's been a few issues with => logic in the record selection formula. It could be you are running into this problem. Look for NOT inserted into your selection formula.
    Oh and SP2 is coming out shortly so it may resolve the issue. But if you want you could purchase a support, or if you have a support contract then create a case in SMP and get a rep to work with you to debug the issue.
    If you have not try the Trial Version of CR 2011, put it on a VM-ware image or Test PC so you don't corrupt anything for production and have a look at and test it in that designer also. If you purchase a case and it is a bug then you'll get a credit back for the case.
    Don
    Edited by: Don Williams on Oct 26, 2011 7:40 AM

Maybe you are looking for

  • Looking for color feedback on new site related to web storefronts

    I'm new to the forums, and getting back into design. I have a new website that will provide reviews of different ecommerce/web storefront solutions and tutorials on setting them up. In addition to technical hurdles to make it easier to use Kuler, I'm

  • Create a new table by joining rows of a given table

    Table1 (id, value1, value2) id value1 value2 1 23 45 2 34 54 3 11 09 new table (id, table1.id, table1.id, product) In other words I am trying to pair up rows in table1 and a new field and form the new table. How do I do this ?

  • Ability to add metadata or label folders

    Maybe I'm missing something, but I can't understand why folders (Mac OS) can't be tagged with metadata. If I have 20 folders - some of which are client A and some are Client B - I'd like to be able to keyword those folders. At the least I should be a

  • After installing the newest update on apple tv, my films don't show up

    I have just installed the latest update on apple tv. Now I find "Music", Podcasts, Videos and Photos on apple tv, but not my films, which are also stored in iTunes - can anybody help me there?

  • Case Structure Sub Label bug ?

    Searching the forum I could not find a post related to this. Whenever something changes in the diagram LV marks the VI as not saved (yet). However, when the Sub diagram label of a Case Structure is changed, text and/or visibility, LV does not mark th