Unpivot multiple products fields data dynamically

Hi,
I am having data as below;
   ID
      CMC
      EMS   
        KBP
Week1
501378
320967
822.54
Week2
13500
6000
3000
Week3
34534
63563
9868
Week4
32523
32532
54223
Week5
235235
53453
34534
Week6
34534
534534
34534
I want to show the above data like below;
Product
    Week1
     Week2
    Week3
    Week4
    Week5
    Week6
CMC
501378
13500
34534
32523
235235
34534
EMS
320967
6000
63563
32532
53453
534534
KBP
822.54
3000
9868
54223
34534
34534
I tried the following query: 
declare @ListWeekData varchar(max)
declare @query nvarchar(max)
SET @ListWeekData = STUFF((SELECT distinct ',' + QUOTENAME(convert(varchar,WeekOfMonth))   
            FROM  #WeeklyBreakupData
            FOR XML PATH(''), TYPE  
            ).value('.', 'NVARCHAR(MAX)')   
        ,1,1,'') 
print @ListWeekData
SELECT @query = 'SELECT Product
  FROM 
  #WeeklyBreakupData
  UNPIVOT
    Producta FOR Product IN (' + STUFF(@ListWeekData, 1, 1, '') + ')
  ) AS up;';
PRINT @query;
 EXEC (@query);
drop table #WeeklyBreakupData
but unable to get the desired result. Please help me out ASAP.
Thanks,
Srini

Here you go
CREATE TABLE tmp (Name CHAR(1),Forecast INT,Stock INT)
INSERT tmp SELECT 'a',100,300  
INSERT tmp SELECT 'b',300,400 
INSERT tmp SELECT 'c',200,250
INSERT tmp SELECT 'd',200,300
-- dynamic pivot (SQL Server 2005/2008)
DECLARE @pivot_cols NVARCHAR(1000);
SELECT @pivot_cols =
        STUFF((SELECT DISTINCT '],[' + Name
               FROM tmp
               ORDER BY '],[' + Name
               FOR XML PATH('')
               ), 1, 2, '') + ']';
DECLARE @pivot_query NVARCHAR(2000);
SET @pivot_query =
N'SELECT * FROM (
SELECT * FROM (
SELECT Name,SUM(Forecast) Forecast,SUM(Stock) Stock FROM tmp
GROUP BY Name ) tmp UNPIVOT
 Col for [GROUP] IN (Forecast,Stock)
) as UnPvt ) pvt
PIVOT (MAX(Col) FOR Name IN (' + @pivot_cols + ')) j'
EXEC(@pivot_query);
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence

Similar Messages

  • Validation of multiple empty fields in dynamic form

    Hi,
    I have created multiple fields dynamic form consisting of both mandatory & optional fields. Since the mandatory fields are validated by default, I want to validate the optional fields while submitting as PDF document dynamically and prompt me to continue or discard the submission. Also validating each & every field is not valid option as my form contains more than 200 fields.
    I have tried with the below script which I successfully used to lock the form but in validating the empty fields I have a problem. Although I populate all the fields in the form, still I receive the validation message. Can anybody help me out on this issue?
    for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) {
    var oFields = xfa.layout.pageContent(nPageCount, "field");
    var nNodesLength = oFields.length;
    // Set the field property.
    for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {
    if (oFields.item(nNodeCount).isNull = 1 && oFields.item(nNodeCount).length < 0){
    xfa.host.messageBox("All the form fields are not completed, Do you want to continue","Field Validation", 2, 2);
    break
    Thanks,
    Jay

    I discovered how to accomplish this using the Manage Dynamic Form Wizard and changed the "Display as" field property from "Text field" to "Text" for the fields I wanted read only.
    Now I have another problem, the properties of one of the fields (for comments) was "Text area" when I changed it to "Text" I now have this extremely long line that streches the width of the browser.
    Is there a way to get this line to wrap? This is he line I'm working with...
    <td class="form_results"><?php echo KT_escapeAttribute($row_rssubmissions['sub_comments']); ?></td>
    Dennis
    I found the answer to this problem, Günter had answered it in another post.
    http://forums.adobe.com/message/1875032#1875032
    Dennis

  • Particular sales order of the same line item hv created multiple production

    sir,
    I am having a problem in MD04. A particular sales order of the same line item hv created multiple production order.and continously planning is going on... I didn't get why it happens.
    Will u please suggest me what should i do in this case?
    Regards
    Meenu

    Hello sir,
    yes, ofcourse, for the finished material have the BOM with some semifinished productes which are to be produced .
    In co02 , we can go through the collective production order.
    One more thing is that, in the multiple production order date(scheduling date) shows in forward(future dates).
    For ex:09-05-2010.
    Regards
    Meenu

  • How to handle multiple fields data

    Hi All,
    My data is :
    FldName           FldTypeCode          Text
    Sandya            02                         nothing
    Raj                 01                         12/Oct/2008
    Lokesh            03                          12546
    Harish             04                          12565.35
    King                01                          12/Nov/2007
    Cobra              02                          texttype In the UI I have give with refcursor all three fields data. now from UI to DB he is passing all values to update at a time.
    Q) Now My question is How to update all the values.
    Eg: Create procedure procdname (ip_allvalues in typerecord)
    is
    begin
    --statements;
    end;
    the above procedure input parameter can handle all three fields data when they pass,
    1) If the parameter handles, which type i need to create ?
    2) How i need to update multiple records at a time?
    Please can any body...
    Thanks in advance..

    sanjuv wrote:
    In the UI I have give with refcursor all three fields data. now from UI to DB he is passing all values to update at a time.
    Q) Now My question is How to update all the values.With an update statement. Identify the row with a where condition and then set the new values. That's one of the first reasons why primary keys are used.
    1) If the parameter handles, which type i need to create ?
    2) How i need to update multiple records at a time? If you don't explain how you User Interface is designed to work nobody can tell you anything about it. Anyway for such things there is no need to define any type.
    Usually the application should submit an update command(like the following one) for each row to update.
    update <table_name>
         set field_1= <value1>,
              field_2= <value2>
              field_n= <valuen>
    where <primary key column> = <primary key value of the row to update>Bye Alessandro
    Edited by: Alessandro Rossi on 6-ott-2008 16.37

  • Custom Fields in the Product Master Data

    Hi Experts!
    I have to add some custom fields in the product master data on SRM and I also need to have this data to be synchronized with the same in ERP.
    After having added this fields, can you pelase suggest a way to syncrhonized them with the ERP? is there a BADI I can leverage as in CRM?
    Thanks in advance.
    Points promised.

    Hi,
    See these related threadS:
    Re: Replicating additional fields (R/3 4.7) to SRM product master
    Transfer Inforecord Conditions Scales  to SRM Product Master
    https://www.sdn.sap.com/irj/scn/threadmessageid=6669812#6669812
    Extending SRM Product Master
    BR,
    Disha

  • Determine Date field format dynamically

    Hello friends,
    I'm writing some database access code in java. The biggest problem I face is date fields. Because I don't know the date field format (For example, in SQL Sever we can have dd/mm/yy or mm/dd/yy, etc), I can't format dates for insert/update statements.
    Is there a way to determine the date field format dynamically? Regardless of database, for ex. MS SQL, Oracle?
    Thank you.

    Hey!
    There is a way to do this! The Oracle Database understands SQL92 Syntax. So you can use
    - {d ?yyyy-mm-dd?} for date representation,
    - {t ?hh:mm:ss?} for time representation,
    - {ts ?yyyy-mm-dd hh:mm:ss.f...?} for timestamp rep.
    Here is a small example:
    // Connect to the database
    // You can put a database name after the @ sign in the connection URL.
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:oci8:@", "scott", "tiger");
    // Create a Statement
    Statement stmt = conn.createStatement ();
    // Select the ename column from the emp table where the hiredate is Jan-23-1982
    ResultSet rset = stmt.executeQuery
    ("SELECT ename FROM emp WHERE hiredate = {d ?1982-01-23?}");
    // Iterate through the result and print the employee names
    while (rset.next ())
    System.out.println (rset.getString (1));I hope this is what you wanted to know!

  • Create Multiple Signature and Date fields with a custom Toolbar Button

    First off, thanks in advance!  I am a scripting newbie and I am trudging my way through with very little experience with scripting of any kind.  I am good at taking other's scripts and forming them into something I need, but I can't seem to find anything to do what I want.
    Using Adobe Acrobat X, I am trying to create a toolbar button that I can press to create multiple signature and date fields with predetermined locations.
    Below is the script I have that is working to create just a single signature box, but I can't seem to figure out the exact syntax to have that same button create multiple fields.  In total it is 9 signature fields and 9 date fields need to be created.  If you can just give me an example of what the button would look like with multiple scripts?  I was assuming I would set up multiple variables and then in the cExec property of the toolbar button I could just call out all of those variables? 
    var sigswm = "addField('sigSWM', 'signature', '0', [108, 198, 494.64, 72])"
    app.addToolButton({cName: "dotbutton", cExec: sigswm, cLabel: "Place Signature and Date Blocks",});
    Thanks in advance for any help you can provide.
    Billy Sweeney

    Thanks!  That was probably the only thing I didn't try.
    I do have one more question.  What I want is when the signature field is clicked it fills out a specific date field. I beleive the script I want would be:
    var currentTime = new Date()
        var month = currentTime.getMonth() + 1
        var day = currentTime.getDate()
        var year = currentTime.getFullYear()
        var signingTime = day +"/"+month+"/"+year
        var f = this.getField("dateSWM"); 
        f.value = signingTime;
    I found this on another thread that mentioned it could be placed in the Signed tab of the signature properties dialog.  I am assuming it would be placed in my button script file as a setAction script for each signature, but I am not real sure exactly where or how?

  • Today's date dynamically entered into text field that user enters additional text into same field.

    Trying to have today's date dynamically entered into a repeating table row textfield when the button is clicked to create each repeating row. The user can then enter addtional text into the same text field next to the date.
    Example:
    [4/25/2012] This is the text the user entered.
    Today's date is populated in each update row created when the "Update Row" button is clicked.
    The following script works but only for the first instance, not the second, third, forth, etc...
    Click event: (JavaScript, client)
    this.resolveNode('Table2._RowB').addInstance(1);
    xfa.resolveNode("Table2.RowB.#subform.Update").rawValue
    Thank you,
    ~Don

    Hi Don,
    Does this solution cover the above problem? https://acrobat.com/#d=VjJ-YsXLKmV6QU84JrAAIw
    Niall

  • Multiple Products on a Single Page

    Hello,
    Back when I built this website http://www.kerrlab.com/ BC didn't support multiple products appearing on a single product page. I worked with a BC vendor on a workaround which wasn't ideal since we had to put actual HTML into the Description field of the Catalog Detail page:
    http://www.kerrlab.com/products-1/equipment/stainless-steel-ovals-and-formers
    Has anything changed over the last two years? Or I'm I just not leveling the BC properly?
    Ideal Structure:
    Parent Catagory - (EX: http://www.kerrlab.com/products/equipment)
    Product Catagory - (EX: http://www.kerrlab.com/products/equipment)
    Product - (EX: http://www.kerrlab.com/products-1/equipment/ultra-waxer-2)
    Products' Skus (EX: http://www.kerrlab.com/products-1/equipment/ultra-waxer-2)
    We are looking to redesign the site and I figured this would be a great opportunity to rework the website structure.
    Thank you,
    Kenneth

    Good day,
    Based from your current layout, i'm pretty sure we still cannot do this on BC.
    Only work around I can see is to use the {tag_grouping}, where customers can choose between products of a certain "product group"
    In this case, you can still use your exisitng product items, and just group them together, and put {tag_grouping} on your Product Detail Layout for customers to choose the items. e.g.
    http://twitterboot.vslaunchpad.com/store/clothing/mens-jacket
    (there is a dropdown to choose the other products)
    Hope this helps
    Cedric

  • Hide multiple rows in a dynamic table based on the row value.

    Hi,
    I need to hide multiple rows in a dynamic table based on the specific value of that row.
    I cant find the right expression to do that.
    please help

    Go to the Row Properties, and in the Visibility tab, you have "Show or hide based on an expression". You can use this to write an expression that resolves to true if the row should be hidden, false otherwise.
    Additionally, in the Matrix properties you should take a look at the filters section, perhaps you can achieve what you wish to achieve through there by removing the unnecessary rows instead of just hiding them.
    It's only so much I can help you with the limited information. If you require further help, please provide us with more information such as what data are you displaying, what's the criteria to hiding rows, etc...
    Regards
    Andrew Borg Cardona

  • Is it possible to create a form with multiple form fields on a single line?

    Is it possible to create a form with multiple form fields on a single line?  I can't find anything in the documentation or a template that does this.
    I am trying to create a "documents received" checklist with a check box on the left margin, a date-received field to the right of the check box and and a description of the document (Formatted Text) on the far right.
    In the past I have entered the Fixed Text with a word processor, published it to a PDF file, then added the check box and date fields with the Acrobat Forms editor.  I would prefer to use FormsCentral if it is possible.

    We now support multiple fields on one line. This post provides a brief overview.
    Give it a try and send us your feedback.
    Sorry it took so long.
    Randy

  • Multiple report fields from single physical column.

    Hi Experts,
    I have a physical table like below. Multiple records for a single customer id. The no of Address_type may increase in future.
    Customer_id     Address_Type         Address
    101                  Primary                   abcdefgh
    101                  Secondary               234oij3mb4
    101                  Billing                      mdmnweoij4
    102................etc.
    My Requirement on OBIEE is to display report as below.
    Customer_ID, Primary_Address, Secondary_Address, Billing_Address.
    101                 abcdefgh            234oij3mb4               mdmnweoij4
    Multiple report fields ( Primary_Address, Secondary_Address, Billing_Address ) are derived from same physical column ADDRESS.
    I tried to duplicate the Address column on the report thrice and added conditions like Address_Type = Primary/Secondary/Billing for those three fields respectively.
    But only of the field is getting correct data and rest of duplicate columns are null.
    Tried FILTER function on OBI Answers, but the function fails saying it should be used only on measures.
    Thought the alternative would be to define multiple logical columns at BMM layer. Created multiple alias for same table at physical layer and correspondingly created LTS for each on a single logical table. Defined Fragmentation/Where conditions.
    LTS1 - Address_Type = PRIMARY
    LTS2 - Address_Type - SECONDARY
    LTS3 - Address_Type - BILLING
    Created multiple logical columns from each LTS like Primary_Address, Secondary_Address, Billing_Address from LTS1, LTS2, LTS3 respectively.
    This time, am getting data for all the fields on the report but getting cartesian result.
    Can someone guide me whether my approach is correct or any other alternate best approach to achieve the desired result.
    Note: I have the data Address on multiple physical rows for a customer, rather Not in a single row. which is causing me problem.
    Thanks...
    Ramchand.

    Hi Srini VEERAVALLI,
    I have lot many other fields in the same report coming from other tables.
    Does the Pivot table option for above mentioned Address fields affect other columns?
    If Yes, Can there be any other alternative? Am thinking of Opaque View at Physical layer to bring all Addresses on a single row.
    Thanks...
    Ramchand.

  • Best Solution for Creating an Onlne Purchase order form with multiple calculation fields

    I am a bit confused.  Our school has a Forms Central account which works great for our registration forms but I need to find a solution for creating an online purchase form with multiple calculation fields - I know that forms central does not support calculation fields (too bad) but I know that Acrobat Pro does... soooo...
    Can you create the forms in Acrobat and then somehow integrate the advanced features into forms central?  Do they talk to each other?  Is this easy to do? .... I guess another way to putting it is can you create the forms in Acrobat including all of the advanced features for payment calculation and then host it online using Forms Central to manage and collect the data? (I guess that really is my question)
    Thanks (how does this compare to a solution like Formstack?)

    Hi, thanks.
    The naming convention was the consistant up until a point when I read that you need a '.' syntax (?!) - does anyone know if this is true?
    Attached is a version with Bernd Alheit's suggestion and with all the naming of the fields being consistant. It's still not working for me though after doing this and I'm stuck as to why, because I think it should work. I've also tried writing the calcualting line of code in the same manner that Bernd Alheit suggests before I came on here, and it wouldn't work then.
    As with any coding, it must be something to which I have done, but I can't see it anywhere
    Any ideas? Thanks for helping me
    Cheers

  • Report to pull multiple Product Categories/Organizational Units per project

    Hi Experts,
    We are facing the following issue.
    We have created a Project and have associated multiple Product Category & Organization to this project, many to One relationship. This we have achieved through customization. When we are pulling report for this project through Reports-> Project Summary Extract. Itu2019s giving us only one Product Category & one Org Unit per Project. The business wants us to pull all the Org Units & the Product categories associated with the Project, when we are displaying the report. This org units & product categories will be shown in Org Unit & Product category columns respectively separated by commas.
    Looking forward for your help.
    Thanks,
    Ritik

    Hi Vikram,
    We have not created any custom fields neither for the Product Categories nor for the Org Unit/Business Unit(T1.BUSINESS_UNIT_OBJECT_NAME). These two fields are already there in the Result fields for the report Project Summary Extract . I am just looking for some way to pull all the Product categories & Business Units associated with the project  in the Product Categories column & in Business Unit column respectively separated by comma or show it as in example 2 given below(in multi rows).
    e.g. 1:
    Project:     Product Categories:
    PROJ1   ->  PC1,PC2,PC3
    Or
    e.g. 2:
    Project:      Product Categories:
    PROJ1        ->                           PC1
    PROJ1     ->                    PC2
    PROJ1     ->                             PC3
    I have already copied the existing query & modified it to achieve the above, but still this is not working. Currently i am querying FCI_MAS_INTERNAL_CAT for Product Categories & FCI_PRO_PROJECTS for projects.
    Can you please provide me any sample query to achieve this functionality. Any help on this is greatly appreciated.
    Thanks,
    Ritik

  • Digital Signature - Auto-Populate Multiple Signature Fields

    Hello,
    I am in the process of testing digital signatures with PDFs.  I have a Topaz Signature Pad working in conjunction with Acrobat 9 and Reader 9 so that I can insert digital signatures with no problems.
    We are wanting to take this a step further and streamline a particular business process.  Does anyone know of a way to have a digital signature auto-populate multiple designated signature fields?  We have about 15 documents that require an employee signature in multiple places and rather than having someone sign a document over and over again, we'd like the option for a single signature that auto-fills in all the required signature fields.
    This doesn't necessarily have to work with Topaz Signature Pads.  I am completely open to other suggestions, products or methodologies for making this work as long as something can be automated to auto-fill multiple signature fields.
    Many thanks to the forum!
    Regards,
    Geoff

    Hi Geoff,
    Maybe there is no need to re-inent the wheel. Auto-population of forms is a feature of SignDoc - se http://www.signplus.com/en/products/signdoc/features.php#Form_Preparation
    Auto-filling of forms is requirement which can be achieved through various processes.
    In combination with Adobe LiveCycle this is executed in the case study of Adobe/SOFTPRO.
    http://blogs.adobe.com/security/2010/01/adobe_secured_customer_showcas_8.html
    http://www.adobe.com/cfusion/showcase/index.cfm?event=casestudydetail&casestudyid=762388&l oc=en_us
    However there are also other ways to move forward depending on the envrionment you are using.
    If you are based in the US you may want to get in touch with Rod Vesling SOFTPROs E-Signature Specialist, based in CA near LA, for a chat. His office phone is 805 435 1214. His email is [email protected]
    Depoending on the deice of Topaz you are usinfg you may start right away as quite a decent number of Topaz tablets are supported by SignDoc. However the best idea might be to give Rod a ring and idscus your business requirements in detail.
    Kind regards
    Joerg

Maybe you are looking for

  • ELEMENTS 11    no work on Mac Book Pro 10.9.5 mavericks

    Now I am completely confused, I have MBP 10.9.5 , first of all my photos went to REVELL/ before  and NOW A Orgainizer took them in? I DID ZERO!  are there still photos on REVELLE? and why now wont this ElEMENTS 11 NOT WORK ON MY MAC? yes I did use a

  • How to configure ldap.ora with multiple ldap contexts

    Hello. My company has recently taken on another environment with it's own LDAP configuration. It's a bit tedious to have to keep switching my ldap.ora for both ldap configurations. Are there any good suggestions for either allowing me to search both

  • Inserting image into table

    hi, i m create table, then create procedure, procedure is successfully compile, but when i m trying to insert image into table it error out. for inserting image i go with EXECUTE insert_image_file(1,'C:\sunset.jpg'); sunset.jpg is image which i want

  • Thin Horizontal Lines visible within PDF file after OCR run

    I print to PDF(Acrobat 9.1 Pro), from an imaging application where the images are stored and managed as 300dpi TIFF(Group 4) B&W. The PDF file is produced with no issues.  At this time I run the OCR process to capture the type written data.  As the O

  • OSB: send dateTime do Java Callout method

    Hi, I have a method in Java that receives a parameter of type java.util.Date and I want to invoke that method in an OSB Java Callout Activity. I receive in the OSB 11g service input an element of type xs:dateTime and I want to send it to the Java met