SQL query to not to exclude NULLS

Hi,
I have a column in table
Type
ABC
XYZ
     -- NULL
     -- NULLWhen I write sql statement to exclude Type = 'ABC', the query also excluding NULLs. How to avoid (include nulls) that?

...or (this is not the best one):
select * from yourtable
WHERE nvl2(type,type,'?') != 'ABC'
select * from yourtable
WHERE decode(type,null,'?',type) != 'ABC'..it's only for 'educational' purpose (an excuse to show the nvl2 and decode functions)
or
    select * from yourtable
    where coalesce(type,'?')!= 'ABC'sorry i stop here now.
select * from yourtable
    where nullif(type,'ABC')= type or type is nullEdited by: user11268895 on Aug 31, 2010 5:10 PM

Similar Messages

  • Class oracle.xml.sql.query.OracleXMLQuery not found in import

    I tried to perform load java using a non-sys user :
    loadjava -user user1/passwd -v -o -r Archive.java
    but encountered the following error:
    Errors in Archive:
    ORA-29535: source requires recompilation
    Archive:11: Class oracle.xml.sql.query.OracleXMLQuery not found in import.
    Info: 1 errors
    loadjava: 3 errors
    But if I use sys user I don't have any error:
    loadjava -user sys/manager -v -o -r Arachive.java
    initialization complete
    loading : Archive
    creating : Archive
    resolver :
    resolving: Archive
    Why is this so?
    ANy security setup that I missed?
    Thanks in advance.
    Note:
    my Archive.java file contains:
    // Core Java Classes
    import java.io.*;
    import java.sql.*;
    // Oracle Java classes
    import oracle.jdbc.*;
    import oracle.jdbc.driver.*;
    import oracle.xml.sql.query.OracleXMLQuery;
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Azman Diron ([email protected]):
    I tried to perform load java using a non-sys user :
    loadjava -user user1/passwd -v -o -r Archive.java
    but encountered the following error:
    Errors in Archive:
    ORA-29535: source requires recompilation
    Archive:11: Class oracle.xml.sql.query.OracleXMLQuery not found in import.
    Info: 1 errors
    loadjava: 3 errors
    But if I use sys user I don't have any error:
    loadjava -user sys/manager -v -o -r Arachive.java
    initialization complete
    loading : Archive
    creating : Archive
    resolver :
    resolving: Archive
    Why is this so?
    ANy security setup that I missed?
    Thanks in advance.
    Note:
    my Archive.java file contains:
    // Core Java Classes
    import java.io.*;
    import java.sql.*;
    // Oracle Java classes
    import oracle.jdbc.*;
    import oracle.jdbc.driver.*;
    import oracle.xml.sql.query.OracleXMLQuery;
    <HR></BLOCKQUOTE>
    Managed to solve this problem.
    Drop all xml objects owned by sys and user1.
    Reload xml objcets for user1 with -force option.
    null

  • SQL Query - The number of columns specified in "SQL Query" does not match t

    I am creating new UDM for tablespace alert, below is my query,however its failing with error
    SQL Query - The number of columns specified in "SQL Query" does not match the value specified in "SQL Query Output"
    I selected Metric type is number
    SQL Query Format : Two columns
    Query:
    SELECT d.tablespace_name,round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2)
    used_pct FROM sys.dba_tablespaces d,(select tablespace_name, sum(bytes) bytes, sum(greatest(maxbytes,bytes)) maxbytes from sys.dba_data_files group by tablespace_name) a,(select tablespace_name, sum(bytes) bytes from sys.dba_free_space group by tablespace_name) f
    WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+)
    AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY');
    Any clues why i am getting error.

    SQL> SELECT d.tablespace_name,round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2) used_pct
    2 FROM sys.dba_tablespaces d,(select tablespace_name, sum(bytes) bytes, sum(greatest(maxbytes,bytes)) maxbytes from sys.dba_data_files group by tablespace_name) a,(select tablespace_name, sum(bytes) bytes from sys.dba_free_space group by tablespace_name) f
    3 WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+)
    4 AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY');
    TABLESPACE_NAME USED_PCT
    MGMT_TABLESPACE .82
    SYSAUX 1.52
    UNDOTBS1 .32
    RMAN .02
    CORRUPT_TS 10.63
    USERS 0
    SYSTEM 2.26
    MGMT_ECM_DEPOT_TS .04
    MGMT_AD4J_TS 0

  • Flash chart with dynamic sql query does not display

    Hi,
    In my schema SIVOA I have a lot of tables declared like this :
      CREATE TABLE "SIVOA"."EVV_xxxx"
       (     "CLEF_VAR" NUMBER(4,0),
         "DATE1" DATE,
         "VALEUR" NUMBER(16,8) Only the last part of the name changes "xxxx". For example E009, E019, etc....
    I am making a chart page with report and want the user to select a name of a table and I will display using dynamic sql query, the table report and chart.
    P184_ENAME is a select list returning the last part of the name of the table, fro example 'E009', 'E019', etc.
    P8_CLEF_VAR is an item containing a value. This value is a key retrieved like this :SELECT CLEF_VAR
    FROM SIVOA.SITE_ECHELLE
    WHERE SITE = :P184_ENAMEI built a classic report using a sql dynamic function :DECLARE
    x VARCHAR2 (4000);
    BEGIN
    x := 'SELECT NULL, DATE1, VALEUR FROM SIVOA.EVV_'
    || UPPER(:p184_ename)
    || ' WHERE CLEF_VAR = :p8_clef_var' ;
    RETURN (x);
    END;:p8_clef_var is an itme containing the value '4544'.
    This works perfectly fine !
    When I use this sql fucytion into a flash chart it does not work. I get this message "No data found".
    I do not understand why a the report get a result and not the chart !
    But if i hard-code the number of the CLEF_VAR instead of fetching it from :p8_clef_var I get a nice chart ! Go figure !DECLARE
    x VARCHAR2 (4000);
    BEGIN
    x := 'SELECT NULL, DATE1, VALEUR FROM SIVOA.EVV_'
    || UPPER(:p184_ename)
    || ' WHERE CLEF_VAR = 4544 ' ;
    RETURN (x);
    I cannot stay with the key (CLEF_VAR) hard-coded unformtunately !
    My question is how to get the chart displaying properly ??
    Thank you for your kind answers.
    Christian                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Alex,
    Using your request, with the classic report I get results (data), but I get the same message with the Flash chart : "No data found" ! I don't know how to investigate this. i tried many things but nothing works.
    Christian
    PS I tried this :
    DECLARE
       X   VARCHAR2 (4000);
    BEGIN
    x := 'SELECT NULL, DATE1, ROUND(VALEUR,2) FROM SIVOA.EVV_'
          || UPPER (:p184_ename) ||
          ' WHERE CLEF_VAR = '
          || :p8_clef_var ||
          ' AND DATE1 BETWEEN TO_DATE ('''
    ||:P8_DATE_DEBUT||''', ''DD/MM/YYYY HH24:MI'') AND TO_DATE ('''
    ||:P8_DATE_FIN||''', ''DD/MM/YYYY HH24:MI'')'
    RETURN (X);
    END; But it does not work either. I could find that the SLQ syntax generated is good becaus I put it into an item which display the return done by the pls/sql.
    What is sttange also with the classic report is that if I do click on next or previous to see another rows, I get the message "No data found". If I try to export the report I get an excel file with "No data fouid".
    Does anybody already tried my "need" here ? i find strange thant I should not be the firs one trying to get a report an tables which name would be "dynamic".
    Tahnk you.
    Edited by: Christian from France on Feb 13, 2009 3:05 AM

  • Last Result from Fulltext SQL Query Search Not Showing

    I am creating a custom search results page for MOSS 2007 (using inline .aspx code - don't ask) that uses Fulltext SQL Queries.  I get the results in a ResultTable (see code below) and then use a DataTable to write code to display it (I could have used
    a DataGrid, I know).
    The problem is that the last result is not showing. So, if it reports that there are 5 results, only 4 will show. I have verified that all 5 results do exist (using a slightly broadened query). If it reports 1 result, none exist in the DataTable that loads
    the result data from the ResultTable.
    FullTextSqlQuery query = new FullTextSqlQuery(site);
    query.ResultTypes = ResultType.RelevantResults;
    query.QueryText = qry;
    query.RowLimit = 50;
    query.StartRow = iPage;
    try
    ResultTableCollection results = query.Execute();
    ResultTable resultTable = results[ResultType.RelevantResults];
    DataTable table = new DataTable();
    table.Load(resultTable, LoadOption.OverwriteChanges);
    int n = resultTable.TotalRows;
    The variable "qry" is a valid SQL Query with the relevant clauses.
    I am using a foreach loop to go through "table" (a DataTable), and so I do not think that I have a "one-off error".
    Any suggestions would be most welcome.

    So in results you have all items but when you are loading it into table (type DataTable) you are loosing one last record.
    1) First you check what data you are getting in resultTable - as you are specifying RelevantResult
    2) Check last index of data in ResultTable collection and try to find out the last index ResultTable, or try to find last index of data in result table
    DataTable.Load method accepts parm of type IDataReader and IDatareader, there are cases it looses records if not read properly..check below links
    http://stackoverflow.com/questions/8396656/why-does-my-idatareader-lose-a-row
    http://msdn.microsoft.com/en-us/library/system.data.datatable.load(v=vs.110).aspx
    <hr> Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL <br/> <b><a href="http://insqlserver.com">Everything about SQL Server | Experience inside SQL Server </a></b>-<a href="http://insqlserver.com">Mohammad
    Nizamuddin </a>

  • The SQL query is not executing

    Hi
    I have the following situation: In a project we designed our reports calling a stored procedure the exits in a MS SQL Server 200 database. The Stored Procedures works fine and when they are used in the report everything works perfectly.
    The reports are being made with CR DEsigner 11, when the designer ends them, ha pass them to me and we put them in our java web application. I open them and even preview them since the Crystal Reprots Perspective of Eclipse and I can see the data, so everything to this point is OK.
    The problem comes when I change of connection, I'm trying to connect every report to the same host and database, and when the reprot is displayed in the browser there is no data. I profile the SQL commands that are executed when the report is requested and I found that the reprot is not executing the stored procedure.
    I guess because i'm connectring the report to the same database and host that was used when the report is created and i'm also passing exactly the same parameters of the stored procedure, then report thinks that it doesn't have executing again becuase it will be the same information.
    SO, i wonder if there is a way to request to the report to execute the sql query every time i have to display it.
    thanks for any help.

    What happens when you try to view the report using a simple viewer.jsp?without changing the connection?
    2009-05-25 14:06:09,250 ERROR com.businessobjects.reports.sdk.JRCCommunicationAdapter -  detected an exception: Error de conexión: [SQLServer 2000 Driver for JDBC]Error establishing socket.
    But the database server is ok, so i think the rpt needs more information to be connect to the database.
    Also what happens if you dont use the data bean and give everything there only?
    The same, the rpt is not executing the stored procedure.
    Did anything change on the RDBMS side? Additional packages, changes to the schema, ownership, etc?
    No, the server is ok and the database is ok.
    If you configure Log4J logging to DEBUG, you should see the database invokes from the Crystal Java engine, specifically the queries sent and the number of rowsets returned. Do you notice any errors?
    I have a problem here with log4j. In my project i'm using spring and with the help of spring i configure log4j, basically with spring is easier to configure log4j.
    I'm telling you this because i have log4j working but when my application reaches the code to change the connection to the rerport, log4j dies and stop sending any message to the stdout or to a log file. I haven't since this behavior in any other app o library. So i want to guess i have something wrong with my log4j or maybe with log4j+spring.
    So, i remove all the code of spring referring to log4j, but the problem with log4j wasn't solved.
    What i will try now is to remove spring from the project.
    This is my log4j.properties:
    log4j.rootLogger=DEBUG, stdout
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

  • Where rownum=2 in my sql query is not working . Why ??

    Hello,
    i am using Oracle 11g .Referring scott schema's emp table.
    I just issued this sql query with the intention to get second highest salary of a employee. But i am unable to understand why my query fails ?
    select rownum,empno,ename,sal from (select empno,ename,sal from emp order by sal desc) where rownum=2;This query is returning no rows . Can you tell why this query is returning no rows ?

    888953 wrote:
    Because you can use ROWNUM only to limit the number of returned records, not to return a specific record.
    So only this has sense (n any number):
    ROWNUM <= n
    or
    ROWNUM = 1 (which is equal to ROWNUM <= 1)
    Anything else will not return a row.As i said ,
    select * from (select rownum rn,empno,ename,sal from (select empno,ename,sal from emp order by sal desc)) where rn=2;this query is working fine.So rownm can be used to return a specific record . Please rectify me if i am wrong .

  • SQL Query is not found in NQQuery.log

    Hi Experts,
    I am created an request and executed. But I could not able to find the Physical SQL Query in the NQQuery.log file under OBIEE_HOME/OracleBI/server/Log directory.
    I am not running the report with Administrator privileges. Any inputs would be appreciated.
    Thanks in Advance.
    Regards
    siva

    Hi Brijesh,
    I tried to set the log level to 4, but still could not able to get the actual physical sql query from NQQuery.log file. Please see the below ( part of the log file)
    +++genericpoweruser:2a0000:2a0003:----2009/08/13 16:30:02
    -------------------- Sending query to database named olap (id: <<16271>>):
    select distinct D1.c2 as c1,
    D1.c3 as c2,
    D1.c4 as c3,
    D1.c1 as c4,
    D1.c1 as c5
    from
    (select count(T3809.ORDER_WID) as c1,
    T15731.COUNTY as c2,
    T15731.STATE as c3,
    T15731.COUNTRY as c4
    from
    WC_ORDER_DT T3781,
    WC_ADDRESS_DT T15731,
    WC_ORDER_FT T3809
    where ( T3781.ROW_WID = T3809.ORDER_WID and T3809.SHIP_TO_ADDRESSES_WID = T15731.ROW_WID and T3781.ORDER_REQUESTED_DATE between TO_DATE('2009-08-12 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') and TO_DATE('2009-08-12 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') )
    group by T15731.COUNTY, T15731.STATE, T15731.COUNTRY
    ) D1
    order by c1, c2, c3
    +++genericpoweruser:2a0000:2a0003:----2009/08/13 16:30:12
    -------------------- Query Result Cache: [59124] The query for user 'genericpoweruser' was inserted into the query result cache. The filename is 'C:\OBIEE\OracleBIData\cache\NQS_VREDDY_733634_59402_00000002.TBL'.
    +++genericpoweruser:2a0000:2a0003:----2009/08/13 16:30:12
    -------------------- Query Status: Successful Completion
    +++genericpoweruser:2a0000:2a0003:----2009/08/13 16:30:12
    -------------------- Rows 446, bytes 98120 retrieved from database query id: <<16271>>
    +++genericpoweruser:2a0000:2a0003:----2009/08/13 16:30:12
    -------------------- Physical query response time 9 (seconds), id <<16271>>
    +++genericpoweruser:2a0000:2a0003:----2009/08/13 16:30:12
    -------------------- Physical Query Summary Stats: Number of physical queries 1, Cumulative time 9, DB-connect time 0 (seconds)
    +++genericpoweruser:2a0000:2a0003:----2009/08/13 16:30:12
    -------------------- Rows returned to Client 446
    +++genericpoweruser:2a0000:2a0003:----2009/08/13 16:30:12
    -------------------- Logical Query Summary Stats: Elapsed time 10, Response time 10, Compilation time 0 (seconds)
    Any inputs would be appreciated. Thanks in Advance.
    Siva

  • Goods Issue - SQL Query will not sum

    I have 3 Goods Issue documents with Document Total for each document 10,000 / 20,000 / 30,000 subsequently.
    I want to make query so that it will display like below - where it shows BOTH each of 3 document value (10000/2000/30000) AND the sum of the 3 documents (60000) like below.
    Doc 1 - 10,000
    Doc 2 - 20,000
    Doc 3 - 30,000
    Total = 60,000
    In addition, I would like the ability to choose date range. Basically, something like
    SELECT Document_Total
    FROM Goods_Issue table
    WHERE the_document_date is between 1-SEP-2011 and 31-SEP-2011
    AND the_reference_is _________________
    I have tried many SQL queries, but it displayed either:
    Doc 1 - 10,000
    Doc 2 - 20,000
    Doc 3 - 30,000
    OR
    Total = 60,000
    Please help.

    @Hendry Wijaya      @GordonDu   @malhaar
    Thanks for helps. The SQL query you provided solved 99% of the problem. I just need to make a tweak on the SQL so that it could display the total on the footer. See screenshot below - I uploaded the pics at imageshack as I don't find a way to attach pics in here.
    [See here - Total_at_Footer|http://i129.photobucket.com/albums/p213/whitesnowbear/AAAA/Untitled-2.jpg]
    Thanks a bunch.

  • SQL Query Report Not working

    Hi,
    I have a region as the type
    "SQL Query (PL/SQL function body returning SQL query)".
    The query works fine for reports if I query two columns. Select 1, 2 from table.
    For some reason if the returning query has more than three columns (select 1, 2, 3 from table), I get an error:
    "report error:
    ORA-01403: no data found"
    Any help would be great. Thanks.

    Hi,
    I've been trying all sorts of things on a test report and the only way that I get extra columns is by including derived columns in the report. Otherwise, even with custom headings, adding or removing columns in the report's PL/SQL adjusts the columns as I would expect.
    Are your extra columns derived or can your report return a varying number of columns?
    Andy

  • Oracle.xml.sql.query.OracleXMLQuery not found

    Hi!
    Sorry, but I got a project to continue and there is an import statement "import oracle.xml.sql.query.OracleXMLQuery;" and this gives me a compilation error...
    What do I need to do, where do I find this class??? Any help?
    //Patricia

    Patricia,
    Did you go through the link
    Re: XML SQL Utility
    You have to put xsu12.jar in the lib directory of the jdev.
    xsu12.jar is in the lib directory of the XDK installation.
    You can download XDK from
    http://www.oracle.com/technology/tech/xml/xdk/software/prod/xdk_java.html
    Just download the XDK kit, get the xsu12.jar from the lib directory and put in the lib directory of the jdev.
    -- Arvind

  • Index (or not) for excluding NULL values in a query

    Hello,
    I have table that can become very large. The table has a varchar2 column (let's call it TEXT) that can contain NULL values. I want to process only the records that have a value (NOT NULL). Also, the table is continuously expanded with newly inserted records. The inserts should suffer as little performance loss as possible.
    My question: should I use an index on the column and if so, what kind of index?
    I have done a little test with a function based index (inspired by this Tom Kyte article: http://tkyte.blogspot.com/2006/01/something-about-nothing.html):
    create index text_isnull_idx on my_table(text,0);
    I notice that if I use the clause WHERE TEXT IS NULL, the index is used. But if I use a clause WHERE TEXT IS NOT NULL (which is the clause I want to use), a full table scan is performed. Is this bad? Can I somehow improve the speed of this selection?
    Thanks in advance,
    Frans

    I build a test case with very simple table with 2 columns and it shows that FTS is better than index access even when above ratio is <= 0.01 (1%):
    DROP TABLE T1;
    CREATE TABLE T1
               C1 VARCHAR2(100)
              ,C2 NUMBER
    INSERT INTO T1 (SELECT TO_CHAR(OBJECT_ID), ROWNUM FROM USER_OBJECTS);
    BEGIN
         FOR I IN 1..100 LOOP
              INSERT INTO T1 (SELECT NULL, ROWNUM FROM USER_OBJECTS);
         END LOOP;
    END;
    CREATE INDEX T1_IDX ON T1(C1);
    ANALYZE TABLE T1 COMPUTE STATISTICS
         FOR TABLE
         FOR ALL INDEXES
         FOR ALL INDEXED COLUMNS
    SET AUTOTRACE TRACEONLY
    SELECT
              C1, C2
         FROM T1 WHERE C1 IS NOT NULL;
    3864 rows selected.
    real: 1344
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=59 Card=3864 Bytes=30912)
       1    0   TABLE ACCESS (FULL) OF 'T1' (Cost=59 Card=3864 Bytes=30912)
    Statistics
              0  recursive calls
              0  db block gets
           2527 consistent gets
           3864 rows processed
    BUT
    SELECT
         --+ FIRST_ROWS
              C1, C2
         FROM T1 WHERE C1 IS NOT NULL;
    3864 rows selected.
    real: 1296
    Execution Plan
       0      SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=35 Card=3864 Bytes=30912)
       1    0   TABLE ACCESS (BY INDEX ROWID) OF 'T1' (Cost=35 Card=3864 Bytes=30912)
       2    1     INDEX (FULL SCAN) OF 'T1_IDX' (NON-UNIQUE) (Cost=11 Card=3864)
    Statistics
              0  recursive calls
              0  db block gets
           5052 consistent gets
           3864 rows processed
    and just for comparison:
    SELECT * FROM T1 WHERE C1 IS NULL;
    386501 rows selected.
    real: 117878
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=59 Card=386501 Bytes=3092008)
       1    0   TABLE ACCESS (FULL) OF 'T1' (Cost=59 Card=386501 Bytes=3092008)
    Statistics
              0  recursive calls
              0  db block gets
         193850 consistent gets
         386501 rows processedHence you have to benchmark you queries with and w/o index[es]

  • SQL query using not equal to or not exists

    Hi All;
    From the  below table , i need to display the client name 
    where output is not equal to Pre Start, BA
    but display client with output only with SOSP
    so only in the below example DEF client name will be displayed
    below is my query
    select C.new_applicationformid,
    C.clientname ,
    C.new_noofappointments
    From (
    Select A.new_applicationformid ,A.new_programmecontractidname,Count(1) As Cnt
    from FilteredNew_applicationform as a
    full outer join filteredNew_Evidence as aa on (a.new_applicationformid = aa.new_relatedapplicationid)
    Group By A.new_applicationformid ,A.new_programmecontractidname
    Having Count(1) >= 1) A
    Inner Join filteredNew_Evidence AA on a.new_applicationformid = aa.new_relatedapplicationid
    Inner Join FilteredNew_applicationform C on C.new_applicationformid = aa.new_relatedapplicationid
    Where ((aa.output in ('SOSP'))
    and (aa.output not in ('Pre Start','BA') )
    Any help much appreciated
    Thanks
    Pradnya07

    See examples written by Joe Celko to help you out
    CREATE TABLE PilotSkills 
    (pilot CHAR(15) NOT NULL, 
     plane CHAR(15) NOT NULL, 
     PRIMARY KEY (pilot, plane));
    PilotSkills 
    pilot    plane 
    =========================
    'Celko'    'Piper Cub'
    'Higgins'  'B-52 Bomber'
    'Higgins'  'F-14 Fighter'
    'Higgins'  'Piper Cub'
    'Jones'    'B-52 Bomber'
    'Jones'    'F-14 Fighter'
    'Smith'    'B-1 Bomber'
    'Smith'    'B-52 Bomber'
    'Smith'    'F-14 Fighter'
    'Wilson'   'B-1 Bomber'
    'Wilson'   'B-52 Bomber'
    'Wilson'   'F-14 Fighter'
    'Wilson'   'F-17 Fighter'
    CREATE TABLE Hangar
    (plane CHAR(15) NOT NULL PRIMARY KEY);
    Hangar
    plane 
    =============
    'B-1 Bomber'
    'B-52 Bomber'
    'F-14 Fighter'
    PilotSkills DIVIDED BY Hangar
    pilot
    =============================
    'Smith'
    'Wilson'
    SELECT DISTINCT pilot  
      FROM PilotSkills AS PS1
     WHERE NOT EXISTS 
           (SELECT *
              FROM Hangar
             WHERE NOT EXISTS 
                   (SELECT *
                      FROM PilotSkills AS PS2
                     WHERE (PS1.pilot = PS2.pilot)
                       AND (PS2.plane = Hangar.plane)));
    SELECT PS1.pilot 
       FROM PilotSkills AS PS1, Hangar AS H1
      WHERE PS1.plane = H1.plane
      GROUP BY PS1.pilot 
     HAVING COUNT(PS1.plane) = (SELECT COUNT(plane) FROM Hangar);
    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

  • An sql query is not working

    Hello everybody,
    I want to enter a word in a table if that word does not already exist in the table.
    I wrote a query like this.
    String word="Football";
    sql="INSERT INTO m_word_list (word_text , category_id , used_counter, date_of_addition, added_by, is_status ) VALUES ('"+word+"', 2, 0, '"+todaysDate+"', '1', '1')WHERE '"+word+"' NOT IN
    (SELECT * FROM `m_word_list` WHERE word_text = '"+word+"');
    Where am I wrong in the query?
    Please help.

    1.) Always post the exception, error message and whatever detail you've got when something "doesn't" work.
    2.) Always use PreparedStatements to execute parameterized queries/updates instead of dynamically building the String
    3.) INSERT INTO doesn't have a where clause.
    Why don't you simply make the wort_text column unique and simply try to insert. If there's already such a word then you'll get a message which tells you.

  • 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