SQL Query if or case omit fields but not line.

I have the below SQL Query my goal is to not show Aging or Storage Date if QTY is greater than 0. 
I know I can omit the line but I still want to show just not those two fields is this possible?
Select sl.SKU, sl.LOC, (editdate) AS "Storage Date", CAST(sysdate-editdate AS DECIMAL(10,2)) AS Aging, sl.QTY, sl.QTYALLOCATED
From skuxloc sl
Where sl.SKU in ('315A6112-29','315A6112-33')
This is what I'm looking for:
Work Smarter Not Harder

Are you working with OracleSQL, There is no sysdate in SQL Server.
Select sl.SKU, sl.LOC,
case when sl.QTY =0 then '' else editdate end AS 'Storage Date',
case when sl.QTY =0 then '' else CAST(sysdate-editdate AS DECIMAL(10,2)) END
AS Aging,
sl.QTY, sl.QTYALLOCATED
From skuxloc sl
Where sl.SKU in ('315A6112-29','315A6112-33')
If you are working with Oracle, You can try decode.
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions040.htm
http://www.dba-oracle.com/t_decode_function.htm
--Prashanth

Similar Messages

  • SQL query can be executed through TOAD but not through Discoverer

    Hallo, everybody:
    Got another problem. A SQL query can be executed through TOAD, but when I want to execute it by a worksheet of Discoverer Plus, it always shows there is no data.
    PS: I copied this query from Discoverer Plus to TOAD, which means, this query is generated through the Discoverer. Does anybody know about how could it be?
    Thank you.
    Geng

    Hi,
    If you are able to get data in TOAD with the same user credential as that of Discoverer Plus then it will implies an issue with Discoverer.
    Else it is privilege issue , your TOAD user has select privilege to the base objects (tables/views etc) where as your Disoverer used does not.
    Compare the privileges granted to these 2 users and you can narrow done to the issue .
    Thanks,
    Sutirtha

  • Sql query to identify transports in dev but not in prod

    I use sqlplus to select fields from saperp.e070v so I can compare transports in prod with those in qa. The purpose is to identify those transports that I need to run when I H-copy prod to QA. I'm using this where clause (TRFUNCTION='K' OR TRFUNCTION='W') . Should I look at TRSTATUS? I'd appreciate any recommendations or ideas. I do not have access to ABAP.

    Thanks Markus.
    Here are the distinct codes I found. Are there any ot these That I need to be concerned about? Is there a Key/Legend for these?
    SQL> select distinct trstatus from saperp.e070v;
    T
    R
    D
    O
    SQL> select distinct trfunction from saperp.e070v;
    T
    W
    R
    P
    K
    D
    Q
    M
    T
    X
    F
    S
    T
    G
    12 rows selected.
    SQL> describe saperp.e070v;
    Name                                      Null?    Type
    TRKORR                                    NOT NULL VARCHAR2(20)
    TRFUNCTION                                NOT NULL VARCHAR2(1)
    TRSTATUS                                  NOT NULL VARCHAR2(1)
    TARSYSTEM                                 NOT NULL VARCHAR2(10)
    AS4USER                                   NOT NULL VARCHAR2(12)
    AS4DATE                                   NOT NULL VARCHAR2(8)
    AS4TIME                                   NOT NULL VARCHAR2(6)
    STRKORR                                   NOT NULL VARCHAR2(20)
    LANGU                                     NOT NULL VARCHAR2(1)
    AS4TEXT                                   NOT NULL VARCHAR2(60)
    CLIENT                                    NOT NULL VARCHAR2(3)
    SQL>
    F
    S
    T
    G
    12 rows selected.
    SQL> describe saperp.e070v;
    Name                                      Null?    Type
    TRKORR                                    NOT NULL VARCHAR2(20)
    TRFUNCTION                                NOT NULL VARCHAR2(1)
    TRSTATUS                                  NOT NULL VARCHAR2(1)
    TARSYSTEM                                 NOT NULL VARCHAR2(10)
    AS4USER                                   NOT NULL VARCHAR2(12)
    AS4DATE                                   NOT NULL VARCHAR2(8)
    AS4TIME                                   NOT NULL VARCHAR2(6)
    STRKORR                                   NOT NULL VARCHAR2(20)
    LANGU                                     NOT NULL VARCHAR2(1)
    AS4TEXT                                   NOT NULL VARCHAR2(60)
    CLIENT                                    NOT NULL VARCHAR2(3)
    SQL>

  • SQL query needed to identify cancelled invoice where distribution lines

    SQL query needed to identify cancelled invoice where distribution lines Debit is not equal Credit line item in particular
    Is there a way from back end FROM ap_invoice_distributions_all where we can find for the cancelled invoice where distribution lines Debit is not equal Credit line item
    Regards,
    Prakash Ranjan

    Hello Prakash
    Can you please see if this query helps you?
    SELECT i.invoice_id, i.invoice_amount, nvl(sum(d.amount),0)
    FROM ap_invoice_distributions_all d, ap_invoices_all i
    WHERE i.org_id = <you org_id>
    AND i.invoice_id = d.invoice_id
    AND d.line_type_lookup_code not in ('PREPAY')
    AND i.cancelled_date IS NOT NULL
    GROUP BY i.invoice_id, i.invoice_amount
    HAVING (i.invoice_amount <> nvl(sum(d.amount),0))
    ORDER BY i.invoice_id asc
    Octavio

  • SQL Query to fetch a specific field in xml

    Hi,
    Below is my sample Xml file.
    <?xml version = "1.0" encoding = "UTF-8"?>
    <methodCall xmlns = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd Schema_new.xsd">
    <methodName>rBatchFile </methodName>
    <params>
    <param>
    <value>
    <struct>
    <member>
    <name>filename</name>
         <value>
         D:\test.txt
         </value>
    </member>
    <member>
    <name>batchId</name>
    <value>
         L1
    </value>
    </member>
    </struct>
    </value>
    </param>
    </methodName>
    </methodCall>
    I want to query a "value" field based on the "name" field. I tried with the following query which didnt work.
    SELECT a.extract('//value/text()' , 'xmlns:="http://www.tibco.com/schemas/CS4_new1/Schema.xsd" ')
    FROM ( SELECT t.customerinfo.extract('//member[name="filename"]','xmlns:="http://www.tibco.com/schemas/CS4_new1/Schema.xsd" ')
    FROM cust_order t ) a;
    Please do provide the SQL query ASAP.

    with tab as (
    select xmltype('<?xml version = "1.0" encoding = "UTF-8"?>
    <methodCall xmlns = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd Schema_new.xsd">
    <methodName>rBatchFile </methodName><params>
    <param>
    <value>
    <struct>
    <member>
    <name>filename</name>
    <value>
    D:\test.txt
    </value>
    </member>
    <member>
    <name>batchId</name>
    <value>
    L1
    </value>
    </member>
    </struct>
    </value>
    </param>
    </params>
    </methodCall>
    ') a from dual
    --end of sample data
    SELECT
      extractvalue(column_value,'/member/name') name,
      extractvalue(column_value,'/member/value') value
    from tab t,xmltable('xmlns = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.tibco.com/schemas/CS4_new1/Schema.xsd Schema_new.xsd"','for $i in //member return $i' passing t.a)An example...but i tweaked the xml...check the xml namespace once before executing...
    without adding the namespaces...code will be like...
    with tab as (
    select xmltype('<?xml version = "1.0" encoding = "UTF-8"?>
    <methodCall >
    <methodName>rBatchFile </methodName><params>
    <param>
    <value>
    <struct>
    <member>
    <name>filename</name>
    <value>
    D:\test.txt
    </value>
    </member>
    <member>
    <name>batchId</name>
    <value>
    L1
    </value>
    </member>
    </struct>
    </value>
    </param>
    </params>
    </methodCall>
    ') a from dual
    --end of sample data
    SELECT
      extractvalue(column_value,'/member/name') name,
      extractvalue(column_value,'/member/value') value
    from tab t,xmltable('for $i in //member return $i' passing t.a)Ravi Kumar

  • SQL QUERY updateable report with APEX_ITEM fields to update hidden columns

    Here is my SQL query:
    select
    "EMPLOYEE_ID",
    "PUBLICATION_ID",
    "TITLE",
    '<NOBR>1. ' || APEX_ITEM.TEXT(101,CODE1,2,3) || '  ' ||
    APEX_ITEM.TEXT(102,CODE1_PCT,2,3) || ' %</NOBR><BR>' ||
    '<NOBR>2. ' || APEX_ITEM.TEXT(103,CODE2,2,3) || '  ' ||
    APEX_ITEM.TEXT(104,CODE2_PCT,2,3) || ' %</NOBR><BR>' ||
    '<NOBR>3. ' || APEX_ITEM.TEXT(105,CODE3,2,3) || '  ' ||
    APEX_ITEM.TEXT(106,CODE3_PCT,2,3) || ' %</NOBR>' rfcd_codes,
    APEX_ITEM.DISPLAY_AND_SAVE(100,CODE1) hidden_rfcd1,
    mycomments
    from "#OWNER#".mytable
    I have 3 code fields with their percentages (_pct). I have concatinated them so I can format them nicely on the page.
    I have create a process 'on-submit and before computations and validations' where I was hoping to assign my table columns (eg the code and pct columns) from the APEXITEMs in my select statement.
    I can get the values from these (APEX_ITEM) fields by referencing APEX_APPLICATION.G_F10(i) etc.... so thats cool.
    But my problem is how do I reference the table columns so I can assign them.
    I am using a 'Multi Row Update' process to perform the update to the database.
    P.S. mycomments column is working fine. It gets updated nicely but its just those other APEX_ITEM fields.

    I don't have the apex_application.g_f01(i) referenced in the page source...In the page source you wouldn't find anything by that name
    Identify the tabular form's checkbox column in the page(firebug/chrome developer panel makes this easy)
    It should be like
    &lt;input id=&quot;...&quot; value=&quot;&quot; type=&quot;checkbox&quot; name=&quot;fXX&quot; &gt;we are interested in the name attribute , get that number (between 01 and 50)
    Replace that number in the code, for instance if it was f05 , the code would use
    apex_application.g_f05
    --i'th checked record' primary keyWhen you loop through a checkbox array, it only contains the rows which are checked and it is common practice to returns the record's primary key as the value of the checkbox(available as the the i'th array index as apex_application.g_f05(i) , where i is sequence position of the checked row) so that you can identify the record.

  • SQL query requested to pull one field out of multiple records

    Post Author: ralph.devlin
    CA Forum: Data Connectivity and SQL
    We use Track IT to manage our ticket base. We have parent work orders and child assignments that I am trying to report on. What I want to do is create a view, or even if this can be done in a formula, is pull data from the main work order, which in our scnerio and accorindg to the database diagrapm is WORKORDERTYPEID = 0, It will pull the TASKS.RESPONS field from that WO. Then it will compare the TASKS.PARETNWOID to WOID and if WORKORDERTYPEID = 1 then it needs to return the TASKS/RESPONS field of that record, and there may be three records or so. Then What I may need it to do is organize it maybe into seperate columns so I can add each one to Crystal keeping in mind that it will need to link those records to main WOID of the parent so it will display on one line. Any ideas
    Ralph

    Post Author: ralph.devlin
    CA Forum: Data Connectivity and SQL
    Ok I tried that and it seemed to work fine, here is an aexample of the data returned
    168458
    Lane, Carrie
    Ralph Devlin
    Ralph Devlin
    168458
    PHX - Training Room
    SM - 8th Fl Conf Room
    NULL
    NULL
    168458
    6/20/2008 3:30:00 PM
    Video Conference
    0
    168458
    Lane, Carrie
    Ralph Devlin
    Luis Estrada
    168458
    PHX - Training Room
    SM - 8th Fl Conf Room
    NULL
    NULL
    168458
    6/20/2008 3:30:00 PM
    Video Conference
    1
    Using the last column which is the workordertypeid, I was able to elimate the first row of data, which is the parent work order, but see how it is returning the technician name twice, where the second row returns me as the primary and then the technician on the assignment WO as well, which I want. In Crystal I have it only selecting the rows with the 1 is the last column, since those rows have the data arranged how I want them to be.
    Once issue that just arose, is what if we only had one work order that we wanted to report on in the subreport. since the WO will get a 0 in the last column, it will never be selected in the report. Is there a way to either us a statement that selects it if it is the only WO listed compared by the WOID field, or if there is a way in SQL, to get what is showing in row 2 to be the only row returned back so I can then show all work orders regardless if they are an assignment
    Here is my current SQL query
    SELECT     T1.WOID, T1.REQUEST, T1.RESPONS, T2.RESPONS AS Addtech, T2.PARENTWOID, T1.LOOKUP2, T1.TaskLookup3, T1.TaskLookup4, T1.TaskLookup5,                       T1.WO_NUM, T1.DUEDATE, T1.WOTYPE3, T2.WorkOrderTypeIdFROM         dbo.TASKS AS T1 LEFT OUTER JOIN                      dbo.TASKS AS T2 ON T2.PARENTWOID = T1.WOID

  • Oracle 10g - query is very slow in jdbc but not in other tools

    I'm using PreparedStatement to execute a query with some parameters.
    in sql developer, it just spends 12 seconds but in jdbc, it's around 140 seconds.
    I disabled "_optim_peek_user_binds" parameter already but it didn't help.
    alter session set "_optim_peek_user_binds"=false;

    Please mark this thread ANSWERED and repost it in the JDBC forum.
    https://forums.oracle.com/forums/category.jspa?categoryID=288
    When you post provide your 4 digit Oracle version, Java version and JDBC jar name and version as well as the code you are using.

  • I need to upload a pdf with more than 500 fields, but not all need to be registered.

    We are working on a pdf to send to our customers. The form has more than 500 fields but we only need to register some of them, the other fields will be filled in the pdf, saved and sent bak to us. Is there any way to do that?
    Thanks in advance.

    I am sorry but there is no way to designate some fields for online collection and others not.
    Andrew

  • SQL*Plus variable assignment works for 8i but not 9i

    We have scripts that connect to each database on the box and perform database tasks nightly. The scripts first set the environment then connects to each database with SQL*Plus. This works for 8i but fails in the recently created 9i environment. (Unix Solaris environment)
    Because the SQL*Plus connection appears in many areas in the scripts, we assign the following connection string to a variable:
    SQLPLUS="/usr/oracle/product/9.2.0/bin/sqlplus -s 'xxx/xxxxxx@xxxx as sysdba'"
    Export SQLPLUS
    echo "$SQLPLUS"
    (This echo out correctly: /usr/oracle/product/9.2.0/bin/sqlplus -s 'xxx/xxxxxx@xxxx as sysdba')
    It fails when the script calls the assigned variable:
    $SQLPLUS <<-EOF
    with the following error:
    Usage: SQLPLUS [ [<option>] [<logon>] [<start>] ]
    where <option> ::= -H | -V | [ [-L] [-M <o>] [-R <n>] [-S] ]
    <logon> ::= <username>[<password>][@<connect_string>] | / | /NOLOG
    <start> ::= @<URI>|<filename>[.<ext>] [<parameter> ...]
    "-H" displays the SQL*Plus version banner and usage syntax
    "-V" displays the SQL*Plus version banner
    "-L" attempts log on just once
    "-M <o>" uses HTML markup options <o>
    "-R <n>" uses restricted mode <n>
    "-S" uses silent mode
    However, if I remove the SQLPLUS variable assignment and changed all occurrence of
    $SQLPLUS <<-EOF to
    /usr/oracle/product/9.2.0/bin/sqlplus -s 'xxx/xxxxxx@xxxx as sysdba' <<-EOF
    Then the script runs successfully. But this solution is cumbersome.
    Any ideas as to how to have the script work with assigning the SQLPLUS variable????
    Any help is appreciated.

    I has an immediate suspicion it might be related to the issue
    mentioned in
    http://otn.oracle.com/support/tech/sql_plus/htdocs/sub_var2.html#2_7
    but this proved wrong: the SP2-306 still occurs in the latest
    SQL*Plus.
    I wonder what version of 8i you had working? With an old SQL*Plus
    8.1.7.0 my connection failed the same as in 9.2 and 10i.
    My solution was to do:
      SQLPLUS='sqlplus -s'
      UNPW='/ as sysdba'
      $SQLPLUS "$UNPW" &lt;&lt;EOF
      EOFThis worked in 9.2.0.5, 10.1.0.2 and 8.1.7.0.
    One common security risk on UNIX remains: putting the username and
    password on the command line. On some systems a "ps" command will
    show the password to any user. If OS authentication cannot be used
    for connection, perhaps putting the username/password in the SQL
    script may be more secure?
    A final note is that in SQL*Plus 10g, no quotes are needed around
    AS SYSDBA, i.e.
      sqlplus / as sysdba works from the OS prompt, whereas in 9.2 you need to do
      sqlplus "/ as sysdba"This makes a solution easy:
      SQLPLUS="/usr/oracle/product/10.1.0/bin/sqlplus -s xxx/xxxxxx@xxxx as sysdba"-- CJ

  • SQL select who works in 4.7 but not 4.6 ?

    Hi all,
    I got the following select statement who works fine on a R/3 4.7 but not in 4.6B (syntax error), any idea ?
      SELECT DISTINCT s~idnrk SUM( s~menge ) m~matnr
            INTO   (stpo-idnrk, stpo-menge, mast-matnr)
            FROM   mast AS m INNER JOIN stpo AS s
            ON     m~stlnr =   s~stlnr
            WHERE  ( m~werks = '0101'
                AND m~stlan = '2'
                AND s~idnrk <> space )
            OR
                   ( m~werks = space
                AND NOT EXISTS ( SELECT *
                                  FROM *mast AS m2
                                  WHERE m2~matnr = m~matnr
                                    AND m2~stlan = m~stlan
                                    AND m2~werks ='0101')
                AND m~stlan = '2'
                AND s~idnrk <> space
         GROUP BY s~idnrk
                  m~matnr.

    HI,
    try this query now and look for the bold lines.
    SELECT DISTINCT s~idnrk SUM( s~menge ) m~matnr
    <b>    INTO (stpo-idnrk,stpo-menge,mast-matnr)</b>
    FROM   mast AS m
    INNER JOIN
    stpo AS s
      ON     m~stlnr =   s~stlnr
      WHERE  ( m~werks = '0101'
         AND m~stlan = '2'
         AND s~idnrk <> space )
         OR
         ( m~werks = space
         AND NOT EXISTS (
         SELECT *  FROM *mast AS m2
         WHERE m2~matnr = m~matnr  AND m2~stlan = m~stlan
                 AND m2~werks ='0101')
               AND m~stlan = '2'
               AND s~idnrk <> space    )
         GROUP BY s~idnrk              m~matnr.
    <b>ENDSELECT.
    </b>
    REgards,

  • SQL patch mismatch: Installed in the PDB but not in the CDB - how to correct?

    I have a 12.1.0.1 database in which I wanted to migrate a number of PDBs to AL32UTF character set. To do this I created a second (temporary) database with the correct characterset, unplugged and re-plugged each PDB and ran the DMA U to migrate the PDBs - all went well.
    I then dropped the first database and built another again with the correct characterset.
    When I unplug and replug the PDBs from the temporary to the new database I get the following PDB violation:
    PDB_ACPT_CLONE     SQL patch 19648840 mismatch: Installed in the PDB but not in the CDB.
    This patch had been applied to the original database and then rolled back before the temporary and new databases were created.
    datapatch shows:
    C:\oracle\product\12.1.0\dbhome_1\OPatch>datapatch -verb
    SQL Patching tool version 12.1.0.1.0 on Wed Jan 21 09:43
    Copyright (c) 2012, Oracle.  All rights reserved.
    Connecting to database...OK
    Determining current state...
    Currently installed SQL Patches:
      PDB CDB$ROOT:
      PDB PDB$SEED:
      PDB PDB_ORCL12C:
      PDB PDB_ACPT_CLONE:
    Currently installed C Patches:
    For the following PDBs: CDB$ROOT
      Nothing to roll back
      Nothing to apply
    For the following PDBs: PDB$SEED
      Nothing to roll back
      Nothing to apply
    For the following PDBs: PDB_ORCL12C
      Nothing to roll back
      Nothing to apply
    For the following PDBs: PDB_ACPT_CLONE
      Nothing to roll back
      Nothing to apply
    SQL Patching tool complete on Wed Jan 21 09:43:44 2015
    C:\oracle\product\12.1.0\dbhome_1\OPatch>
    PDB_ORCL12C was created in the new database.
    The moved PDB is now stuck in RESTRICTED mode.
    Any ideas on how to resolve this?

    Are you sure all PDBs were open when the patch was applied?
    The more common issue is when one version of Apex is installed in the root and a different version installed in a PDB and the PDB is plugged in.

  • Mandatory for Visable field but not for hidden field

    Hi All,
    I have a couple of radio buttons (Yes and No) when the user selects Yes they are then prompted for the date this happend.
    How can i make the Date field mandatory if they select yes but not if they select no. I have tried making the date field mandatory but it throughs the obvious error if it is hidden.

    Hi George, thanks for your reply.
    The way i hide and show the date box at the moment is by using the Show/Hide field action under the properties of the radio buttons.
    Thx

  • SQVI - Join tables using similar fields (but not same)

    Hi folks!
    I would like to know if there is a way to do a join between two tables thru fields that are similar but not exactly the same. For example, I need to join tables EKKO and CDHDR, where the PO numbers do exist in both the tables (EKKO-EBELN and CDHDR-OBJECTID), but the fields are different. Is it possible to achieve such kind of a join?
    Appreciate your help.
    Regards,
    Anwar.

    >
    Mohammad Anwar wrote:
    though their data type is the same (CHAR).
    unfortunately it is not enough... You have to select separately from the two tables and merge the data somehow in the program.

  • SBO SQL Query outputs zero values as nulls but need the zeros

    Hi all,
    I'm having a problem with a query I'm writing in SBO where if the field contents are zero, these are output as null.
    I have a field for the stock usage on sales orders and ont too for production orders, but if I add these together they only provide a result if both columns contain a numeric value.
    I've tried adding "0" to the column value, adding and subtracting "1" and also multiplying the value by "1" but still no joy.
    I have also tried adding a "cast" statement to the column, but that doesnt seem to have an effect either (I think as this is more an output function).
    I need to be able to use these columns as separate displays in addition to being used in a further column as part of a calculation.
    If anyone has an idea how I can output a true zero value as opposed to a null value your help would be appreciated.
    Cheers,
    J

    Hello Julian,
    You could try to use a CASE Statement as I have shown below and test this will the SQL below.  If you use the T0.LineNum without any CASE or CAST the LineNum 0 will show as blank in SAP.
    SELECT
    CASE WHEN T0.LineNum != 0 THEN CAST(T0.LineNum AS VARCHAR(10)) ELSE '0' END AS 'Row Number',
    T0.ItemCode AS 'Item No.', T0.BaseQty AS 'Base Quantity', T0.PlannedQty AS 'Planned Quantity - Rows'  FROM  [dbo\].[WOR1\] T0

Maybe you are looking for

  • How to print a message in forms in oracle apps

    Hi all i am using oracle apps r12 In when button trigger how to print a message when the button is pressed. I tried message('HELLO'); this works in oracle forms but in oracle apps its different and i searched so for and used like this fnd_message.set

  • Why won't Lion include e-mail attachments?

    Help!!  Lion won't include e-mail attachments.  Does anybody know of a fix for this?

  • Adobe Flash crashes almost instantly. it is upto date and enabled. Help

    I have uninstalled it and reinstalled it with no change. I send a crash report every time. Don't know what to do! Help please.

  • How to release Purchase requisition..URGENT..

    Hi guru's good morning to all,. I have created PR in my development (100).further i want to create PO for the same .But while creating PO , the shows the PR is not released. Can anybody support me how to release PR in Development.iTried in ME54N.. Th

  • Server Locator Service Failed to Start

    Received Event ID:4380 on single Exchange Server (once part of a DAG but no more - removed other servers and the DAG). Error reads: 'net.tcp://huntsvr.huntelectric.local:64337/Exchange.HighAvailability'. Error A TCP error (10013: An attempt was made