Help need to write script min and group by

 I want to see min  first print date on last column  for instance Wild Attire INc  there should be 5/30/2014 for all records and for clear vision optical 2013/11/13 for all records belongs to clear vision optical integration name if only
one record then keep same like Qball 12/1/2014
select ISNULL(RQPPrintAmountQpYTD,0)+ISNULL(VLQPPrintAmountQpYTD,0) as [Qualified Volume 2014],isnull(PrintamountallYtd,0)+ISNULL(VLQPPrintamountALLYTD,0) as [Total Volume 2014], integration_id as [Integration ID], integration_name as [Integration Name], left([First Print Date],10) as [First Print Date] from #Po
Qualified Volume 2014
Total Volume 2014
Integration Name
First Print Date
0
1.93
Qball
12/1/2014
34446.98
277285.35
Wild Attire, Inc.
5/30/2013
522236.08
530125.78
Wild Attire, Inc.
8/22/2013
3861.06
40820.82
Wild Attire, Inc.
10/24/2014
2087.14
20783.46
Wild Attire, Inc.
10/30/2014
1296.95
24272.81
Wild Attire, Inc.
11/26/2014
1457.96
1512.71
Jackeez.com LLC
12/14/2013
15.27
37206.62
PrintingforLess.com
4/3/2014
9109.85
20631.28
M.A.I.L., Inc
12/16/2013
294.59
2278.32
B2SIGN, Inc.
11/17/2014
37.71
151.48
SpiralScout LLC
11/25/2014
93960.2
94110.38
Clear Vision Optical
11/13/2013
140349.03
140445.65
Clear Vision Optical
1/31/2014
14898.35
14898.35
Clear Vision Optical
3/18/2014
790.59
790.59
Clear Vision Optical
5/9/2014

Hi MarkSubedi,
Your requirement has been extracted and formatted as below, correct me if there's anything wrong.
I want to see min first print date on last column. For instance Wild Attire INc,there should be 5/30/2014. And 2013/11/13 for all records belongs to clear vision optical integration name.If only one record then keep same like Qball 12/1/2014.
Based on my understanding, the below code can help to achieve your requirement.
DECLARE @Table TABLE
([Qualified Volume 2014] NUMERIC(18,2),
[Total Volume 2014] NUMERIC(18,2),
[Integration Name] VARCHAR(99),
[First Print Date] DATE
INSERT INTO @TABLE VALUES (0,1.93,'Qball','12/1/2014');
INSERT INTO @TABLE VALUES (34446.98,277285.35,'Wild Attire, Inc.','5/30/2013');
INSERT INTO @TABLE VALUES (522236.08,530125.78,'Wild Attire, Inc.','8/22/2013');
INSERT INTO @TABLE VALUES (3861.06,40820.82,'Wild Attire, Inc.','10/24/2014');
INSERT INTO @TABLE VALUES (2087.14,20783.46,'Wild Attire, Inc.','10/30/2014');
INSERT INTO @TABLE VALUES (1296.95,24272.81,'Wild Attire, Inc.','11/26/2014');
INSERT INTO @TABLE VALUES (1457.96,1512.71,'Jackeez.com LLC','12/14/2013');
INSERT INTO @TABLE VALUES (15.27,37206.62,'PrintingforLess.com','4/3/2014');
INSERT INTO @TABLE VALUES (9109.85,20631.28,'M.A.I.L., Inc','12/16/2013');
INSERT INTO @TABLE VALUES (294.59,2278.32,'B2SIGN, Inc.','11/17/2014');
INSERT INTO @TABLE VALUES (37.71,151.48,'SpiralScout LLC','11/25/2014');
INSERT INTO @TABLE VALUES (93960.2,94110.38,'Clear Vision Optical','11/13/2013');
INSERT INTO @TABLE VALUES (140349.03,140445.65,'Clear Vision Optical','1/31/2014');
INSERT INTO @TABLE VALUES (14898.35,14898.35,'Clear Vision Optical','3/18/2014');
INSERT INTO @TABLE VALUES (790.59,790.59,'Clear Vision Optical','5/9/2014');
;WITH CTE AS
SELECT [Integration Name],MIN([First Print Date]) [Min First Print Date],COUNT(1) cnt FROM @Table GROUP BY [Integration Name]
SELECT [Integration Name],CASE WHEN CNT=1 THEN T.[Qball Min First Print Date] ELSE [Min First Print Date] END [Min First Print Date] FROM CTE
CROSS APPLY (SELECT [Min First Print Date] AS [Qball Min First Print Date] FROM CTE WHERE [Integration Name]=N'Qball') AS T
ORDER BY CNT,[Integration Name]
In your case, the data seems from the the statement query in your post. If the statement is fine, the below query can be ready to use.
;WITH DataSrc AS
SELECT ISNULL(RQPPrintAmountQpYTD,0)+ISNULL(VLQPPrintAmountQpYTD,0) as [Qualified Volume 2014],isnull(PrintamountallYtd,0)+ISNULL(VLQPPrintamountALLYTD,0) as [Total Volume 2014], integration_id as [Integration ID], integration_name as [Integration Name], left([First Print Date],10) as [First Print Date] from #Po
CTE AS
SELECT [Integration Name],MIN([First Print Date]) [Min First Print Date],COUNT(1) cnt FROM DataSrc GROUP BY [Integration Name]
SELECT [Integration Name],CASE WHEN CNT=1 THEN T.[Qball Min First Print Date] ELSE [Min First Print Date] END [Min First Print Date] FROM CTE
CROSS APPLY (SELECT [Min First Print Date] AS [Qball Min First Print Date] FROM CTE WHERE [Integration Name]=N'Qball') AS T
ORDER BY CNT,[Integration Name]
By the way, there're some columns don't make any sense if what you'd like is just the min(First Print Date), you can remove them.
If you have any question, feel free to let me know.
Best regards,
Eric Zhang
TechNet Community Support

Similar Messages

  • I need help! I have iPad mini and I can't use App Store. It always asking my credit card lnformation to download, but the apps I will download are free. I don't know how it will work again.

    I need help!
    I have iPad mini and I can't use App Store.
    It always asking my credit card lnformation to download, but the apps I will download are free.
    I don't know how it will work again.
    Help me please!
    Thank you.

    You need to have a payment method on file. If the apps are free you will not be charged anything. Either enter your credit card information or purchase and enter an iTunes gift card.

  • Troubleshoting help needed:  My iMac keeps crashing and restarting with a report detail: "spinlock application timed out"  What can I do to fix this?timed out"

    Troubleshooting help needed:  My iMac keeps crashing and restarting with a notice: "Spinlock application timed out"  What can I do?

    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the page that opens.
    Select the most recent panic log under System Diagnostic Reports. Post the contents — the text, please, not a screenshot. In the interest of privacy, I suggest you edit out the “Anonymous UUID,” a long string of letters, numbers, and dashes in the header and body of the report, if it’s present (it may not be.) Please don't post shutdownStall, spin, or hang reports.

  • Hi, I need to install Adobe Flash Player because the version I have installed in my Mac Os is old, but I can´t because I need to write my email and my password and I don´t remember my password, so what can I do?

    Hi, I need to install Adobe Flash Player because the version I have installed in my Mac Os is old, but I can´t do it because I need to write my email and my password and I don´t remember my password, so what can I do? Thank you

    The email and password will be the ones for your computer's security, not something for any Adobe product.  You might need to consult Mac customer support if you are unable to determine the required information.

  • Help needed in writting Customer exit - ABAP Code

    Hi Friends,
    I have a scenario in one of the query and need to write a customer exit for the same. Here is the scenario:
    I am using one input variable XXX to get input from user which feeds value to one of the charateristic  lets say "CHAR1" in query. I have one more characteristic "CHAR2" which has to get the value from the same variable XXX. This is not allowed in BI7.0 as the variable is Hierarchy Node type. It gives error that "Variable XXX is used for two different characteristics."
    So i need to create one more vaiable YYY which will get the value from XXX and then YYY will feed value to CHAR2.  I would appreciate if some one could tell me step by step how to write customer exit and give me the piece of ABAP code i need to write in my case.
    Your help will be appreciated in terms of points.
    Thanks,
    manmit

    Hi Arun,
    1. What should CHAR2 take - Hierarchy node variable or something else ?
    --> CHAR2 is a simple charateristic
    2. In your scenario - why have CHAR1 and CHAR2 ? why not have the user enter values against CHAR2 ??
    --> We dont want user to enter two input as the input values for both Chars are same.
    3. Did you try using a replacement path variable with the CHAR2 variable taking values from Variable on CHAR1 ?
    --> In BI7.0 replacement path variable only take values from Query results. So not able to do the same.
    Thanks

  • Help needed to write control file.

    Hi Guys,
    i need to write one control file to upload data from .txt file to oracle table.
    .txt file data contains like this
    2006041110:40:22
    2006041111:30:42
    2006041210:40:22
    i need to upload this data into date column in oracle table.
    please help me to write control file for this requirement.
    Thanks for your help and time

        data1        "to_date(:data1, 'YYYYMMDDHH24:MI:SS')"

  • Column displays going down. Need it to go across and group together.

    I have an Oracle report I've created and I'm trying to get certain columns of data to display only for the first row and grouped together going horizontally. It's hard for me to explain in words what I need to be done. I could email some screen shots explaining if someone is willing to help me. Thanks in advance!

    What about using the report functionality itself?
    Create the report as Group Left vendor wise and for the Repeating Frams of field Class_Code set the Print Direction to Across/Down and the Horizontal Elasticity to Variable and for all the Parent Frames same. Then it should work as expected.
    Or keep the report tabular and use the formula column as below...
    DECLARE
      CURSOR Fetch_Codes IS
      SELECT class_code
      FROM table_name
      WHERE vendor = :vendor;
      vClsCodes table_name.class_code%TYPE;
    BEGIN
      FOR Get_Codes IN Fetch_codes LOOP
       vClsCodes:=vClsCodes||Get_Codes.class_code||', ';
      END LOOP;
      RETURN vClsCodes;
    END;In the layout editor use this formula column as source of class codes.
    -Ammad

  • Help needed with rman script

    Hi guys,
    I need you help in creating rman scripts.
    my plan is the following:
    - at night i would like to make a backup of the database, archivelogs, control file and spfile. then delete the archivelogs on disk.
    - during the day i would like to make every hour, a backup level 1, archivelogs and crontrol file.
    my questions are:
    for the night backup is the following script ok?
    run {
    set command id to 'xxx';
    allocate channel t1 type 'SBT_TAPE';
    allocate channel t2 type 'SBT_TAPE';
    BACKUP INCREMENTAL LEVEL 0 DATABASE;
    sql 'ALTER SYSTEM ARCHIVE LOG CURRENT';
    change archivelog all;
    backup archivelog all delete input;
    backup current controlfile;
    BACKUP SPFILE;
    release channel t1;
    release channel t2;
    and for the daily backup (run on every hour) what do you think about this? is it ok?
    run {
    set command id to 'xxx';
    allocate channel t1 type 'SBT_TAPE';
    allocate channel t2 type 'SBT_TAPE';
    BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
    sql 'ALTER SYSTEM ARCHIVE LOG CURRENT';
    backup archivelog all not backed up 1 times;
    backup current controlfile;
    release channel t1;
    release channel t2;
    please help.
    Message was edited.

    Hi Alanm,
    Right now the DB is generating many archives, that doesn't mean that we cant adapt the script in the future if less archives are generated.
    By saying "You don't have to make the archive log script an incremental 1 backup" you mean that, since we are already making a backup at night to the archives, theres no need to make them also during the incremental 1?
    and for the rest, do you thing the script is ok?

  • Urgent help needed!! Layout table and Draw layout cell dissapeared.

    I need some urgent help. I'm using CS3 but for a while my
    Layout Table and Draw Layout Cell icons appear greyed and can't use
    them at all. Is there any kind soul out there who knows how to fix
    this? I'm going nuts trying all the possible options but none seem
    to work.
    Help please!!!!!!

    > How would you about designing a page without using html?
    You don't. But I don't recall suggesting that you not use
    HTML. I just
    suggested that you use best-practice HTML, no? Or maybe you
    meant to ask
    how you would go about building your site without learning
    HTML? In that
    case, I think you are outta luck. Using DW without knowing
    HTML is a very
    punishing experience, I'm afraid.
    > PS: A virtual box of 12 bottles of Moet Chandon is
    already on your way!!
    I'd prefer Cristal, please.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "Untersberg" <[email protected]> wrote in
    message
    news:g4tj9a$m5o$[email protected]..
    > Ahhhhhh!!!!! They came up!!!! They came up again!!
    > I was on standard mode. Now going back to your
    suggestion, which I really
    > appreciate. How would you about designing a page without
    using html? I'm
    > just
    > redesigning my website at the moment and need it to get
    going urgently,
    > hence
    > the reluctance to start learning HTML at the moment.
    I'll do after but I
    > need
    > to get this up and running fairly quickly.
    >
    > Cheers.
    >
    > PS: A virtual box of 12 bottles of Moet Chandon is
    already on your way!!
    >

  • Help Needed in Creating Java Class and Java Stored Procedures

    Hi,
    Can anyone tell how can i create Java Class, Java Source and Java Resource in Oracle Database.
    I have seen the Documents. But i couldn't able to understand it correctly.
    I will be helpful when i get some Examples for creating a Java Class, Java Source and Stored Procedures with Java with details.
    Is that possible to Create a Java class in the oracle Database itself ?.
    Where are the files located for the existing Java Class ?..
    Help Needed Please.
    Thanks,
    Murali.v

    Hi Murali,
    Heres a thread which discussed uploading java source file instead of runnable code on to the database, which might be helpful :
    Configure deployment to a database to upload the java file instead of class
    The files for the java class you created in JDev project is located in the myworks folder in jdev, eg, <jdev_home>\jdev\mywork\Application1\Project1\src\project1
    Hope this helps,
    Sunil..

  • Help needed in sap script

    Hi friends,
    I`ve assigned the script name and driver program in NACE tcode for ME21N transaction.
    When I print preview from ME21N tcode and keep script debugging active it goes into debugging mode ...Here it shows script name same as what has been assigned in NACE but the contents which are being debugged are different than the actual script contents .. means the code which we can see while debugging the script are not matching with the code of the same named script in SE71.
    Can anybody help me out regarding this issue .. ?
    thanks .

    Hi,
    I think this is because your the transaction ME21N is calling the language version of the script based on the language maitained in the communication tab(header) of the document. To ensure this, when your script is going into debugging mode just check whther it is calling the same language version of script that you are intending.
    Regards,
    KK

  • Help needed to write a dialog program

    Hello ABAP Gurus,
    I am very much new to ABAP Programming.
    Can anybody help me to write a simple Dialog Program ??
    I have a database table.
    I have created a screen with screen painter, and kept some input fields & a push button in it.
    I want to fill the database table with the data entered into the fields on the screen.
    When the user enters the data and  presses  the PUSH BUTTON then that data record should be stored into the Database table.
    So what kinda code I have to write in PAI (Process After Input),  to achieve this functionality ??
    The help will be greatly appreciated.
    Thanks in advance
    Best regards
    Ravi
    Edited by: Ravi Kiran on Oct 28, 2009 2:17 PM

    It's easy:
    In PAI you have do an insert into a database table, following the steps:
    1.on PAI  create a module: for exemple Zwrite_table.
    2. inside Zwrite_table code as follow:
    move var1 to wa_table-var1.
    move var2 to wa_table-var2.
    move var3 to wa_table-var3. etc etc
    insert table ztable from wa_table.
    P.s. ztable is a database table.
    wa_table is a structure that have the same structure of ztable.
    var1 var2 var3 etc is a variable inside your dynpro.
    regards,
    Roberto.

  • Help needed to write in excel sheet

    Hi,
    I currently need to read a table and write it in a file.
    iam able to do it by using UTL package.The utl file also writes in xls format.but if a record has two column.
    both the columns are written in a single column in excel
    sheet.Kindly suggest me how to solve this problem
    Thanks in advance.

    1. spool a file with 'csv' extension using Sql*Plus.
    2. Use a delimiter for columns.
    For example,
    select '"'||column1||'","'||column2||'"'
    from mytable

  • Help needed with 3rd party software and Windows XP on MacBook

    My Brother embroidery software has stopped working on the XP side of my MacBook. After all kinds of uninstalling and installing with support from Brother, they decided the problem is not the software and I should "contact my computer company." Since this is really a Mac, would Apple be able to help me with a Windows issue? The genius bar said no, Microsoft says no, so what is the point of buying a using a dual platform machine if no one takes responsibility for helping? I'm very frustrated and could use help from someone who works on both platforms.

    *"would Apple be able to help me with a Windows issue?"*
    Sorry, but no. Apple does not support third party operating systems and applications.

  • Help needed on UCCX Script

    Hi All,
    I am adding one new script on IPCCX 7.0. Can some help to understand the function of the following:
    DateList=Create File Decument "C:\Program Files\wfavvid\Documents\user\en_US\" + calendar + ".xml")
    When I run reactive bedug I can see the following error output:
    Can some please help me how this script work.
    Apprecaite your quick response.
    Regards,
    Nirmal

    Hi Brian,
    This seems to be I am missing Calender string value. If I set this to business, now look good.
    Once again thanks for your support.
    Regards,
    Nirmal

Maybe you are looking for