Output of a query

Hi,
I have the following query:
SELECT site
FROM ( SELECT date_1, date_2, site
FROM test
ORDER BY 1 DESC)
WHERE ROWNUM < 10;The result has 9 rows with some A or B
I want to print
- successful if I get A's and B's
- unsuccessful if I get only A's or only B's
How can I achieve that ?
Thanks for your help

Assuming site is either A or B:
SELECT  site,
        case count(distinct site) over()
          when 2 then 'successful'
          else 'unsuccessful'
        end
  FROM  (
         SELECT  date_1,
                 date_2,
                 site
           FROM  test
           ORDER BY 1 DESC
  WHERE ROWNUM < 10;If site can be other than A and B:
SELECT  site,
        case count(distinct case when site in ('A','B') then site end) over()
          when 2 then 'successful'
          else 'unsuccessful'
        end
  FROM  (
         SELECT  date_1,
                 date_2,
                 site
           FROM  test
           ORDER BY 1 DESC
  WHERE ROWNUM < 10;SY.

Similar Messages

  • Procedure to save the output of a query into excel file or flat file

    Procedure to save the output of a query into excel file or flat file
    I want to store the output of my query into a file and then export it from sql server management studio to a desired location using stored procedure.
    I have run the query --
    DECLARE @cmd VARCHAR(255)
    SET @cmd = 'bcp "select * from dbo.test1" queryout "D:\testing2.xlsx;" -U "user-PC\user" -P "" -c '
    Exec xp_cmdshell @cmd
    error message--
    SQLState = 28000, NativeError = 18456
    Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'user-PC\user'.
    NULL
    Goel.Aman

    Hello,
    -T:
    Specifies that the bcp utility connects to SQL Server with a trusted connection using integrated security. The security credentials of the network user,
    login_id, and password are not required. If
    –T is not specified, you need to specify
    –U and –P to successfully log in.
    -U:
    Specifies the login ID used to connect to SQL Server.
    Note: When the bcp utility is connecting to SQL Server with a trusted connection using integrated security, use the
    -T option (trusted connection) instead of the
    user name and password combination
    I would suggest you take a look at the following article:
    bcp Utility: http://technet.microsoft.com/en-us/library/ms162802.aspx
    A similar thread regarding this issue:
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/b450937f-0ef5-427a-ae3b-115335c0d83c/bcp-connection-error-sqlstate-28000-nativeerror-18456?forum=sqldataaccess
    Regards,
    Elvis Long
    TechNet Community Support

  • Output of SQ01 Query to a file in background

    Hello,
           I have created a SQ01 query for a certain specific outpur from my SAP system. I need to get the output of this query to a file. While i have tried executing this report from the frontend; it works smoothly, and based on the variant it creates the output and writes to a file at a remote location. But while i am trying to process the same query using background job, it creates a spool request and doesnt export the data to a file.
           Can someone please help me in getting me right in case i am doing anything wrong.
    Regards,
    V

    Hi,
    SAP have created a standard program RSTXPDFT4 to convert your Sapscripts spools into a PDF format.
    Specify the spool number and you will be able to download the sapscripts spool into your local harddisk.
    It look exactly like what you see during a spool display.
    Please note that it is not restricted to sapsciprts spool only.  Any reports in the spool can be converted using the program 'RSTXPDFT4'.
    Regards,
    Pavan

  • Xml output of a query

    Hi,
    I want to generate xml output of a query.
    ( suppose if i write select * from tab1 ; then i want all the rows from the table tab1 in xml form )
    how to do it.. ?
    plz guide.

    I guess what you are loooking for is this
    select xmltype(cursor(select * from dept)).getclobval() from dual;
    this will give you the outout in a txt viewable format.
    Rushi

  • Problem Calling MaxDB stored procedure with output from MII Query template

    Hi,
    I am using Max DB Database studio to write stored procedure, I am calling stored procedure from MII Query using CALL statement.
    Can anyone guide me how to pass output values of stored procedure.
    Examlpe::
    call ProcName('[Param.1]','[Param.2]','[Param.3]','[Param.4]','[Param.5]', :isSuccess, :Trace)
    In the above line of code I am not able to get the output values of stored procedure that is isSuccess and Trace values in Query template when executed. But same thing I get when executed in Database studio.
    How do I call with outputs for any stored procedure in MII.
    Any help would be appriciated.
    Thanks,
    Padma

    My call statement is like this
    call RESULTDATA_INSERT('[Param.1]','[Param.2]','[Param.3]', :isSuccess, :Trace)
    I am able to insert record in DB, But I am not getting output values in Query template.I have done this in Fixed Query, when I execute it throws me "Fatal error as Loaded content empty".
    I tried giving select below call but it dont work.
    Regards,
    Rao

  • Procedure output like a query in SQL developer?

    Hi!
    How can a PL procedure create output like a query in SQL developer?
    This block
    begin
    for record in (
    select * from my_db
    loop
    dbms_output.put_line(record.name ' ' || record.address)
    end loop;
    end;
    would print a of names and adresses in my_db. However, output sent to a query result window which would be the result of
    select name,address from my_db;
    How could I make the PL block behave the same way as the SQL query, i.e. present its output in a query result window?

    Welcome to the forum!
    Please provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION) wheneve you ask a question.
    Do you mean query a procedure as if it were a table?
    You can do that with a pipelined function. Here is sample code you can test using the SCOTT schema
    -- type to match emp record
    create or replace type emp_scalar_type as object
      (EMPNO NUMBER(4) ,
       ENAME VARCHAR2(10),
       JOB VARCHAR2(9),
       MGR NUMBER(4),
       HIREDATE DATE,
       SAL NUMBER(7, 2),
       COMM NUMBER(7, 2),
       DEPTNO NUMBER(2)
    -- table of emp records
    create or replace type emp_table_type as table of emp_scalar_type
    -- pipelined function
    create or replace function get_emp( p_deptno in number )
      return emp_table_type
      PIPELINED
      as
       TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
        emp_cv EmpCurTyp;
        l_rec  emp%rowtype;
      begin
        open emp_cv for select * from emp where deptno = p_deptno;
        loop
          fetch emp_cv into l_rec;
          exit when (emp_cv%notfound);
          pipe row( emp_scalar_type( l_rec.empno, LOWER(l_rec.ename),
              l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno ) );
        end loop;
        return;
      end;
      /Then you can query the function as if it were a table
    select * from table(get_emp(20))Is that what you were looking for?

  • Spooling the output of a Query with out displaying the rows

    Hello All,
    Is it possible to spool the output of
    a query/dbms_output.put_line with out displaying
    the Query output on the console.
    In my case,list of rows in the output is huge, I want
    to eliminate displaying the output of query
    so that spooling will complete faster.
    Thanks in advance.
    -Srini

    You can do:
    SET TERMOUT OFFIn your script before doing the spool command.
    You will have to write your query as a .SQL script and run it from SQL*Plus in order for it to work the way you expect.
    sqlplus -s username/password @query_script.SQL

  • Emailing output of a query

    Hi All,
    please could you guide me on how can I get an email with output of a query?
    Ex : select * from abc
    the above query output, i'd like to get in a table form to my email. please help.
    Thanks in Advance
    Vinod Mallolu
    Cheers, Vinod Mallolu

    There's a good example of this on msdn in the
    sp_send_dbmail documentation
    DECLARE @tableHTML NVARCHAR(MAX) ;
    SET @tableHTML =
    N'<H1>Work Order Report</H1>' +
    N'<table border="1">' +
    N'<tr><th>Work Order ID</th><th>Product ID</th>' +
    N'<th>Name</th><th>Order Qty</th><th>Due Date</th>' +
    N'<th>Expected Revenue</th></tr>' +
    CAST ( ( SELECT td = wo.WorkOrderID, '',
    td = p.ProductID, '',
    td = p.Name, '',
    td = wo.OrderQty, '',
    td = wo.DueDate, '',
    td = (p.ListPrice - p.StandardCost) * wo.OrderQty
    FROM AdventureWorks.Production.WorkOrder as wo
    JOIN AdventureWorks.Production.Product AS p
    ON wo.ProductID = p.ProductID
    WHERE DueDate > '2004-04-30'
    AND DATEDIFF(dd, '2004-04-30', DueDate) < 2
    ORDER BY DueDate ASC,
    (p.ListPrice - p.StandardCost) * wo.OrderQty DESC
    FOR XML PATH('tr'), TYPE
    ) AS NVARCHAR(MAX) ) +
    N'</table>' ;
    EXEC msdb.dbo.sp_send_dbmail @recipients='[email protected]',
    @subject = 'Work Order List',
    @body = @tableHTML,
    @body_format = 'HTML' ;
    Hope that helps

  • Get the output of a query in a textpad..

    Hi..
    I need to get the output of a query in a notepad..
    Can anyone help me..

    spool c:\emp.txt
    fire select * from emp;
    spool off;
    go to c: and check your text file.
    hare krishna
    Alok

  • "Save output of a query in Substitute variable"

    Hi All,
    I am using oracle11g r1 on windows platform. i want to know how can i save the output of a query in a substitute variable so that i can user that variable in other query .i am using this query and i want to store the output in *"&Schema*" variable.
    select substr('D:\activities\expLive_vikash',23,instr('D:\activities\expLive_vikash','0')-22) from dual;
    Thanks & Regards,
    Vikash chauradia(junior DBA)

    Thanks for replyng..
    i am using this in sqlplus prompt . actually i am using a batch file to cange the dump .
    DEFINE FILE_NAME=&file_name; -- This will ask the Dump file name as an input.
    declare Schema varchar2(20);
    begin
         select substr('&&file_name',23,instr('&&file_name','0')-22) into Schema from dual; -- this will give the Schema name as an output.
    dbms_output.put_line(Schema);
    end;
    Drop user &&Schema Cascade;--(Now i am facing the problem in this line. I am not getting Schema name to drop)
    Can u tell me what's the problem in this Script.

  • I want to just spool output of a query only

    now when i try to use spool command, query, output and spool off command also get spooled into the specified filename.
    for ex:
    SQL>spool <filename>.txt
    SQL>select * from dual;
    SQL>spool off
    but the content of output file is:
    select * from dual;
    DUMMY
    X
    spool off;
    i just want output of the query, nothing else, i.e.,
    DUMMY
    X
    plz, suggest me soln.

    Save this script in a text file
    Call the script...
    O/P will be stored in xx.txt
    script
    set feedback off
    set echo off
    spool xx.txt
    select * from dual;
    spool off
    set echo on
    set feedback on
    (You can find the same answer if search in the forum)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Output of One Query  is input to other Query??

    Hi All,
    How to make output of one query as input to other Query and what are the points to be takeb care of to do it?
    regards,
    murali.
    Message was edited by: Murali

    Hallo
    You got a second query where you also have 0date. Based on the selection on the second query, you get some value for 0date. this values are then passed in background to the first query which will show you the output based on the input date of the first query. You can also have othe variable in the query.
    http://help.sap.com/saphelp_nw04/helpdata/en/e3/e60138fede083de10000009b38f8cf/frameset.htm
    I hope everything is fine.
    Mike

  • How to use output of one query as an input for another

    Hi Gurus,
    can you give me any links on how to use an output of one query as an input for another (preferably if this can be done in a dynamic/on the fly way)?
    thanks

    You can use Replacement Path Variable for this purpose. See this detailed documentation.
    http://help.sap.com/saphelp_nw04s/helpdata/en/bd/589b3c494d8e15e10000000a114084/content.htm
    Abhijit
    Edited by: ABHIJIT TEMBHEKAR on Nov 19, 2008 9:48 AM

  • How to get this output using sql query?

    Hi,
      How to get this output using sql query?
    Sno Name Age ADD Result
    1 Anil 23 delhi Pass
    2 Shruti 25 bangalor Pass
    3 Arun 21 delhi fail
    4 Sonu 23 pune Pass
    5 Roji 26 hydrabad fail
    6 Anil 28 delhi pass
    Output
    Sno Name Age ADD Result
    1 Anil 23 delhi pass
    28 delhi pass

    Hi Vamshi,
    Your query is not pretty clear.
    write the select query using Name = 'ANIL' in where condition and display the ouput using Control-break statements.
    Regards,
    Kannan

  • Formatting output display of query designer 7.0

    Hi,
    I have just switched over to Query Designer 7.0 from 3.5. The output of a query shows only 4 columns as against almost a full page of columns in the previous version. Is there a way to increase the default number of columns displayed?
    Thanks

    Hi,
    do you see less rows in your query or BEx workbook?
    Try this:
    Open BEx Analyzer and Open BEx Query Designer. Choose in Query designer your querie and press "Exit and use querie" -> The querie is executed in BEx Analyzer with a default workbook. If there are not all rows displayed like in query definition u may have zero suppression for rows activated. This means if there are no values in one row its simply not displayed. -> Disable it in Querie properties tab rows/lines.
    2nd way:
    Another cause could be that u have to refresh Dataprovider in Analysis grid on BEx Analyzer.
    Go to Design mode (press icon with Capital A in BEx Toolbar)-> right click on Analysis grid (table) -> properties-> Change Dataprovider-> click on button"assign query"-> choose your query and save.
    Hope it helps
    Regards

  • Label styled output by select query

    Hi,
    How do i get output of select query of EMP table of scott schema as below :
    Using Oracle 10g on windows xp machine :
    1.  EMPNO:7499                    2.   EMPNO:7521                    3.   EMPNO:7566
        ALLEN                         WARD                         JONES     
        SALESMAN                         SALESMAN                         MANAGER     
        HIREDATE:20-FEB-81                    HIREDATE:22-FEB-81                    HIREDATE:02-APR-81     
        SAL:1600                         SAL:1250                         SAL:2975
    <<<<BLANK LINE 1>>>>  This is not part of output
    <<<<BLANK LINE 2>>>>
    <<<<BLANK LINE 3>>>>
    <<<<BLANK LINE 4>>>>                                                  
    4.  EMPNO:7654                    5.   EMPNO:7698                    6.   EMPNO:7782
        MARTIN                         BLAKE                         CLARK     
        SALESMAN                         MANAGER                         MANAGER     
        HIREDATE:28-FEB-81                    HIREDATE:01-MAY-81                    HIREDATE:09-JUN-81     
        SAL:1250                         SAL:2850                         SAL:3000
    <<<<BLANK LINE 1>>>>  This is not part of output
    <<<<BLANK LINE 2>>>>
    <<<<BLANK LINE 3>>>>
    <<<<BLANK LINE 4>>>>                                        Means, i wish to print the addresses of my address table; so here i am giving you EMP as example that how it will create create above output if :
    (A) suppose above it is in 3 columns; i wish to change in N number of columns?
    (B) above there are 4 blank lines, i wish to change in N number of blank lines?
    (C) above order by empno, i wish to change in any order by column as well.
    Thanking you,
    Regards
    Nisha Sharma

    WITH t AS (
               SELECT  e.*,
                       ROW_NUMBER() OVER(ORDER BY CASE :order_indicator
                                                    WHEN 1 THEN to_char(empno,'9999')
                                                    WHEN 2 THEN ename
                                                    WHEN 3 THEN job
                                                    WHEN 4 THEN to_char(hiredate,'yyyymmdd')
                                                  END
                                        ) rn
                 FROM  EMP e
    SELECT  REPLACE(SYS_CONNECT_BY_PATH(RPAD(TO_CHAR(rn,'999') || '.  EMPNO:' || empno,30),','),',') ||
            CHR(13) || CHR(10) || '       ' ||
            REPLACE(SYS_CONNECT_BY_PATH(RPAD(ename,30),','),',') ||
            CHR(13) || CHR(10) || '       ' ||
            REPLACE(SYS_CONNECT_BY_PATH(RPAD(job,30),','),',') ||
            CHR(13) || CHR(10) || '       ' ||
            REPLACE(SYS_CONNECT_BY_PATH(RPAD('HIREDATE:' || TO_CHAR(hiredate,'DD-MON-YY'),30),','),',') ||
            CHR(13) || CHR(10) || '       ' ||
            REPLACE(SYS_CONNECT_BY_PATH(RPAD('SAL:' || sal,30),','),',') ||
            LPAD(CHR(13) || CHR(10),2 * :blank_lines,CHR(13) || CHR(10)) line
      FROM  t
      WHERE CONNECT_BY_ISLEAF = 1
      START WITH mod(rn,:column_count) = 1
      CONNECT BY rn = PRIOR rn + 1
             AND level <= :column_count
    /For example:
    SQL> SET LINESIZE 132
    SQL> SET PAGESIZE 0
    SQL> VARIABLE column_count NUMBER
    SQL> EXEC :column_count := 3;
    PL/SQL procedure successfully completed.
    SQL> VARIABLE order_indicator NUMBER
    SQL> EXEC :order_indicator := 1;
    PL/SQL procedure successfully completed.
    SQL> VARIABLE blank_lines NUMBER
    SQL> EXEC :blank_lines := 6;
    PL/SQL procedure successfully completed.
    SQL> WITH t AS (
      2             SELECT  e.*,
      3                     ROW_NUMBER() OVER(ORDER BY CASE :order_indicator
      4                                                  WHEN 1 THEN to_char(empno,'9999')
      5                                                  WHEN 2 THEN ename
      6                                                  WHEN 3 THEN job
      7                                                  WHEN 4 THEN to_char(hiredate,'yyyymmdd')
      8                                                END
      9                                      ) rn
    10               FROM  EMP e
    11            )
    12  SELECT  REPLACE(SYS_CONNECT_BY_PATH(RPAD(TO_CHAR(rn,'999') || '.  EMPNO:' || empno,30),','),',') ||
    13          CHR(13) || CHR(10) || '       ' ||
    14          REPLACE(SYS_CONNECT_BY_PATH(RPAD(ename,30),','),',') ||
    15          CHR(13) || CHR(10) || '       ' ||
    16          REPLACE(SYS_CONNECT_BY_PATH(RPAD(job,30),','),',') ||
    17          CHR(13) || CHR(10) || '       ' ||
    18          REPLACE(SYS_CONNECT_BY_PATH(RPAD('HIREDATE:' || TO_CHAR(hiredate,'DD-MON-YY'),30),','),',') ||
    19          CHR(13) || CHR(10) || '       ' ||
    20          REPLACE(SYS_CONNECT_BY_PATH(RPAD('SAL:' || sal,30),','),',') ||
    21          LPAD(CHR(13) || CHR(10),2 * :blank_lines,CHR(13) || CHR(10)) line
    22    FROM  t
    23    WHERE CONNECT_BY_ISLEAF = 1
    24    START WITH mod(rn,:column_count) = 1
    25    CONNECT BY rn = PRIOR rn + 1
    26           AND level <= :column_count
    27  /
       1.  EMPNO:7369                2.  EMPNO:7499                3.  EMPNO:7521
           SMITH                         ALLEN                         WARD
           CLERK                         SALESMAN                      SALESMAN
           HIREDATE:17-DEC-80            HIREDATE:20-FEB-81            HIREDATE:22-FEB-81
           SAL:800                       SAL:1600                      SAL:1250
       4.  EMPNO:7566                5.  EMPNO:7654                6.  EMPNO:7698
           JONES                         MARTIN                        BLAKE
           MANAGER                       SALESMAN                      MANAGER
           HIREDATE:02-APR-81            HIREDATE:28-SEP-81            HIREDATE:01-MAY-81
           SAL:2975                      SAL:1250                      SAL:2850
       7.  EMPNO:7782                8.  EMPNO:7788                9.  EMPNO:7839
           CLARK                         SCOTT                         KING
           MANAGER                       ANALYST                       PRESIDENT
           HIREDATE:09-JUN-81            HIREDATE:19-APR-87            HIREDATE:17-NOV-81
           SAL:2450                      SAL:3000                      SAL:5000
      10.  EMPNO:7844               11.  EMPNO:7876               12.  EMPNO:7900
           TURNER                        ADAMS                         JAMES
           SALESMAN                      CLERK                         CLERK
           HIREDATE:08-SEP-81            HIREDATE:23-MAY-87            HIREDATE:03-DEC-81
           SAL:1500                      SAL:1100                      SAL:950
      13.  EMPNO:7902               14.  EMPNO:7934
           FORD                          MILLER
           ANALYST                       CLERK
           HIREDATE:03-DEC-81            HIREDATE:23-JAN-82
           SAL:3000                      SAL:1300
    SQL> EXEC :column_count := 4;
    PL/SQL procedure successfully completed.
    SQL> EXEC :blank_lines := 2;
    PL/SQL procedure successfully completed.
    SQL> /
       1.  EMPNO:7369                2.  EMPNO:7499                3.  EMPNO:7521                4.  EMPNO:7566
           SMITH                         ALLEN                         WARD                          JONES
           CLERK                         SALESMAN                      SALESMAN                      MANAGER
           HIREDATE:17-DEC-80            HIREDATE:20-FEB-81            HIREDATE:22-FEB-81            HIREDATE:02-APR-81
           SAL:800                       SAL:1600                      SAL:1250                      SAL:2975
       5.  EMPNO:7654                6.  EMPNO:7698                7.  EMPNO:7782                8.  EMPNO:7788
           MARTIN                        BLAKE                         CLARK                         SCOTT
           SALESMAN                      MANAGER                       MANAGER                       ANALYST
           HIREDATE:28-SEP-81            HIREDATE:01-MAY-81            HIREDATE:09-JUN-81            HIREDATE:19-APR-87
           SAL:1250                      SAL:2850                      SAL:2450                      SAL:3000
       9.  EMPNO:7839               10.  EMPNO:7844               11.  EMPNO:7876               12.  EMPNO:7900
           KING                          TURNER                        ADAMS                         JAMES
           PRESIDENT                     SALESMAN                      CLERK                         CLERK
           HIREDATE:17-NOV-81            HIREDATE:08-SEP-81            HIREDATE:23-MAY-87            HIREDATE:03-DEC-81
           SAL:5000                      SAL:1500                      SAL:1100                      SAL:950
      13.  EMPNO:7902               14.  EMPNO:7934
           FORD                          MILLER
           ANALYST                       CLERK
           HIREDATE:03-DEC-81            HIREDATE:23-JAN-82
           SAL:3000                      SAL:1300
    SQL>     SY.
    Edited by: Solomon Yakobson on Oct 25, 2009 6:02 AM

Maybe you are looking for

  • Problem with solaris management console

    I have installing solaris 9 x86 12/02 on my PC. After start solaris management console 2.1 and after loged in as root, smc display this message: System Information is not able to connect to the server because the WBEM server daemon does not appear to

  • Formats for video and pictures

    Friends I am new to iMovie. I want to create a video for You Tube  and purchase images and video from online sites.  I understand about the different resolutions but I have some questions 1. - Can you see the differance between 1920/1080 (HD) and 720

  • Master-detail problem in ADF JSP

    Is there any way I can add a detail record in a master-detail JSP page without having to open a new page?ž Milos

  • Functionality in SAP to allow you to print multiple copies of a form

    I've been asked by a SD functional team member how to:  This is the table and field names for  Number of Messages functionality in SAP which should allow you to print multiple copies of a form at one time. Program Name:SAPMV13B Screen #:0211 Transpar

  • Color mangement problem using 10.6.4 and CS5

    (i've posted the same problem in Adobe's photoshop forum but I'm also trying here with Apple's users since it might be a problem between 10.6 and the xerox drivers... maybe...) hi ! im in charge of a big print lab in a university. All macpro quad run