SQL clause 'or '.

Hello

I am creating a search function vi, which allows the user to search for some columns in my database with the input control 1. Is it possible to do if some of the columns have different data as string types & digital?

I have this here vi which I use to interrogate some of the column of the same type of data in the database. It seems that there is something wrong with my 'or' clause. When the input is b / l, the part of the data displayed is correct since the firstname column won't work & the clause "and" name also will not work, resulting in all data displayed. However, if I remove the or clause for my lastname, firstname column column will work but my data for the device will not work. When the input is 1, all occupants in my database will be displayed & they will all have the same unit even if they live in a different unit. However, if I delete my request first name, leaving only the unit, it works perfectly.

I believe that the problem happens if I use the or clause of these terms before the last clause "or" & after the last 'or' clause in my query will not work. The Address.AddID AND = PersonDetails.AddID AND PersonDetails.Status = 'active' is ignored if it is not the last clause 'or '.

IM using data select vi to recover my data, because it is something strange happens if I use the sql execute query vi. below is my sql query & attached is my base data & vi.

WHERE Address.Unit = 'b' or PersonDetails.FirstName LIKE '% b %' or PersonDetails.LastName LIKE '% b %' AND Address.AddID = PersonDetails.AddID AND PersonDetails.Status = 'active '.

Thanks for reading & hope someone knows why this happens.

Kind regards

Wayne

I can't open your files (got an earlier version), but I suppose you use an .mdb you have access? Do the work in question here? I have several times to build an access issue and switched to the sql mode to copy in LabView.

Maybe a couple of brackets to fix the problem. It should not be necessary, but it might help to use WHERE ([or CLAUSES]) AND ([CLAUSES AND])

/Y

Tags: NI Software

Similar Questions

  • any case when and the sql clause

    Hello:
    What follows is my sql clause:
    SELECT T.*, b.name
    OF dbtest1 t
    LEFT OUTER JOIN dbtest b ON t.NO = b.empno
    WHERE t.ChineseName like '% "| : ChineseName | ' %' AND b.name like "%" | : name | » %'
    ORDER BY t.ChineseName

    The main problem is that I want to check the b.name if it is null, it can be passed as function NVL, so I try using case when, but it does not work.
    When there are the b.name in where clause, the columns of result will not include data without b.name (or implies the b.name is NULL); And that
    the result data are not entirely accurate.
    is it possible to use the case when it is implemented in the following code snippet:

    -case when b.name is not NULL then b.name like "%" | : name | » %'
    Else b.name = NULL (b.name = b.name does not seem to work on the analysis of data zero)
    end

    Thank you very much.

    962769 wrote:
    The main problem is the table is the form of the cross, and the like clause will filter the
    data without a name. Basically, it should show the empty columns, however, it won't.
    so, when I test the sql code, I fhound Like "%" | b.Name | ' %' will not get the data when the original dbtest1 table data
    has no id corresponding to the BD test. It seems pointless to go the LEFT OUTER JOIN.

    Thank you

    WHERE t.ChineseName like '%'||:ChineseName||'%'
    AND  (
            b.name like '%'||:name||'%'
           or b.empno is null
        )
    
  • These SQL clauses are equivalent?

    Hi, previously I was working in a SQL statement that returns potentially 1 million rows. The 'order by' clause contributes significantly the cost when I checked its plan to explain.
    select ...
    from ...
    order by field1, field2, field3;
    Then I found another way to make the order of who has much lower costs to explain the plan.
    select ...
    , dense_rank() over (order by field1, field2, field3) overall_order 
    from ...
    order by overall_order;
    Both queries took a long time to run if I didn't not wait until this one is over. The question I have is the above two methods will return the same result in the same order? I know dense_rank() returns the same number of ranking if two values are the same, but do not know what 'order by' will do in the same situation.

    I found that when the result set is small (say, a few hundred lines), the analytic function actually result in a higher cost to explain plan. Please let know us if it is OK to use the second method to achieve the effect of "order by" for the large result set.

    If you have better alternatives, please suggest as well. Thank you.

    Hello

    Two of these methods do the same thing.

    Both are for an indefinite period as to what happens when two or more rows have the same values for the three variables.
    Say the lines A, B and C all have exactly the same values for field1, field2, and field3.
    Say, you are running the version with ' ORDER BY Field1, Field2, formees3 ' and the output, in order, is A, B, C.
    If you run one version, then there is no guarantee that you will again get the same order (A, B, C). You can get the same order, or you might not.

    I'd be surprised if "ORDER BY overall_order" was faster than ' ORDER BY Field1, firld2, field3.

  • The USE of dynamic SQL clause

    Hi all
    I'm moving a table as a variable in dynamic SQl but with no result. Suppose that I it running on HR diagram example:
    declare
    sql_state varchar(100);
    hire_date date;
    temp_table varchar(9):='employees';
    
    begin
    sql_state:= 'select hire_date from :1 where employee_id=206';
    
    execute immediate sql_state into hire_date using temp_table;
    dbms_output.put_line('hire_date is '||hire_date);
    end; 
    
    declare
    *
    ERROR at line 1:
    ORA-00903: invalid table name
    ORA-06512: at line 9
    I get this error of invalid table name without knowing what was read for the variable. Any advice?

    Best regards
    Val

    Hi Valerie,

    To add to what Peter, said

    "Binding" values in a query is done for a specific purpose, and this purpose is so that the optimizer can use the same query as the previous execution plan runs the query, which prevent it from having to analyze the hard the query each time. A query execution plan is based on the tables and columns are presented in the query, but with respect to the actual "values" of these columns, they are unlikely to change the execution plan. So, to keep the same execution plan, the query must seem identical (in terms of a query string) like the previous series, so if you want the same query, but just with different values, they can be replaced with bind variables (these things have a ': ' character) and then the values passed in the query, when it is run.

    Now, if Oracle were to allow you to link in the names of objects, such as tables, this means that it could not use the previous execution plans, because he doesn't know until run time what tables will be consulted. Therefore, it would be useless link in the values of the query and it would be just as quick to implement your query string by concatenating all the values inside rather than link them. Considering that a query is parsed first and then the values in it, then it cannot be analyzed if the tables are not known everything first. (Take a look at how queries are formed and variables when you use the DBMS_SQL package).

    So the key thing to remember is that, when it comes to bind variables, you can bind only the 'values', not 'objects '.

  • JOIN the SQL clause

    Hello

    I have a small question:

    INNER JOIN can be written with just the keyword JOIN?

    For example,.

    INNER JOIN table_b b ON a.col = b.col

    OR

    JOIN table_b b ON a.col = b.col

    Thank you

    Yes it is JOIN table_b b WE a.col = b.col or INNER JOIN table_b b ON a.col = b.col

    Published by: orant575 on June 28, 2009 13:27

  • Setting of outsourcing work is not for a SQL Where clause

    Im trying to outsource the WHERE SQL clause of a snapshot data (connecting to Siebel DB) and specify where clause in the run profile that does not work.

    Snapshot of research: Select the name of siebel.s_org_ext

    Parameter of outsourcing: where_clause_sql

    Run the content of the profile:

    phase. Phase1.snapshot.clt.where_clause_sql = name = "ABC0009".

    #phase. Phase1.snapshot.clt.snapshot_sql = select name from siebel.s_org_ext where name = 'ABC0009 '.

    The above parameter retrieves all the records in the table. Below the profile execution retrieves just this record that seems to work fine.


    Run the content of the profile:

    phase. Phase1.snapshot.clt.snapshot_sql = select name from siebel.s_org_ext where name = 'ABC0009 '.


    I want to outsource only where clause as there are many SQL and they are huge to maintain in the run profile.

    I have attached a doco with screenshots that will help to understand more.

    Hello

    You must BE

    -Choose "Select table or view" in the table of the snapshot Wizard selection page

    &

    -Use outsourced where clause

    OR

    -Choose "SQL" in the snapshot table selection wizard page.

    &

    -Outsourced use SQL snapshot

    You can't mix and match options.

    Kind regards

    Nick

  • How to close the popup window after executing PL/SQL?

    Hello

    To see a junior question: we use APEX 5.0.2

    On a page of the modal dialog (of an interactive report), for the button create, I created a dynamic action that runs the specific code from PL/SQL to insert a new item.  Then behind the insert clause, I have the code to close the pop-up window, so that it executes successfully the insert clause without closing the window.  Please let me know what I can do.  Thank you.

    HTP.p ("< script > '");

    HTP.p ('window.opener.Location.Reload ();) Window.Close ();') ;

    HTP.p ("< /script >" ");

    Kind regards

    Jian

    OK, thanks for all your help and ideas. Finally, I gave up running JavaScript, instead, I created another dynamic action that closes the dialog box with a later sequence (for example, it runs after the PL/SQL code).  Now, it closes the windows properly after running pl/sql clause.  Although I still wonder how to run JavaScript because it doesn't do anything, even when I create a process to run javascript directly.

  • Add where clause dynamically

    Hi Experts,

    I have a VO with query like select * ministries dept, emp where dept.dept_id = emp.dept_id group... by order of dept.dept_id employees

    At runtime, I need to add where clause with (and in dept.dept_id (select dept_id from table2))

    I tried to use the vo.setWhereClause () method. But it does not work

    Is there another solution?

    I use Jdeveloper 12.1.3

    Thanks in advance.

    There are various possible solutions for this. You can either use setQuery that defines the entire sql statement. However, you then need to delete where condition adding yourself too.

    Or you use viewCriteria as explained in this blog http://www.ahsanscorner.com/content/2015-11-16-1942-simulating-sql-clause-adf-viewcriteria-api.

    Another approach is described by this blog Jet binary: using bind variable for SQL statements with the paragraph who uses a SQL table to build the in clause.

    Timo

  • There is no possibility of ambiguity in the SELECT clause because any identifier in the SELECT clause must be a database column name

    Hello

    Doc Oracle says the following on the identifiers in the SELECT in PL/SQL clause: there is no possibility of ambiguity in the SELECT clause because any identifier in the SELECT clause must be a database column name.

    If we assume that only valid column identifier are allowed in the SELECT clause.

    But I tried the following:

    DECLARE
    toto NUMBER := 10;
    tata NUMBER := 0;
    BEGIN
    SELECT toto INTO tata FROM employees WHERE employee_id = 101;
    DBMS_OUTPUT.PUT_LINE(tata);
    END;
    /
    

    And there is no error telling me that toto is not a column in the employees table and the result is the same as: toto: = aunt;

    Won't the doc or did I just miss something?

    Thanks for your response!

    Hello

    rep0ne wrote:

    Hello

    Doc Oracle says the following on the identifiers in the SELECT in PL/SQL clause: there is no possibility of ambiguity in the SELECT clause because any identifier in the SELECT clause must be a database column name.

    If we assume that only valid column identifier are allowed in the SELECT clause.

    Post a link to this Oracle doc.

    But I tried the following:

    1. DECLARE
    2. Toto NUMBER: = 10;
    3. Auntie NUMBER: = 0;
    4. BEGIN
    5. SELECT toto IN Auntie FROM Employees WHERE employee_id = 101;
    6. DBMS_OUTPUT. Put_line (Auntie);
    7. END;
    8. /

    And there is no error telling me that toto is not a column in the employees table and the result is the same as: toto: = aunt;

    ...

    You're right that toto is an identifier, but this isn't a column name.  (Of a subquery) column alias are not database of the names of columns either, nor are the names of the user-defined function.

    Also, there is a possibility for ambiguity even if all the names are the database column names.

    Won't the doc or did I just miss something?

    I can't say until I see the doc you're talking about.

    Oracle documentation is sometimes misleading and sometimes just plain wrong.  For each mistake outright example that I saw in the docs of Oracle, there might be 20 cases where the meaning is unclear or misleading and maybe 200 where I just read it wrong.

  • Conditional SQL

    Oracle 11g.

    In General to know where sql clause, such as: where account_id = p_acct_id means that for a specific account_id.  Now, I want to build provided that is a flag setting s = p_flag ' use

    where ID_compte = p_acct_id, otherwise account_id will be ignored.

    For example:

    If using mutiple instruction is like this

    If (p_flag = the of ') then

    Select in...

    where account_id = p_acct_id and p_oth_id = other_id

    on the other

    Select in...

    where other_id = p_oth_id

    end if;

    But, how can I write it in a where clause?



    Thank you

    Hello

    Here's another way:

    WHERE (account_id = p_acct_id

    OR NVL (p_flag, 'OK'). = s "

    )

    AND other_id = p_oth_id

    This will work even if p_flag and/or account_id is NULL.

    CASE expressions are really practical in the SELECT and ORDER BY clauses, because they allow you to do an if-then-else logic in these places.

    WHEN the clauses have their own way of doing if-then-else logic, so the CASE expressions are not necessary much in WHERE clauses.

  • Decimal separator in the SELECT Clause

    Hello

    I have the following parameters of decimal number:

    SQL > select value
    2 from v$ nls_parameters
    3 where parameter = "NLS_NUMERIC_CHARACTERS;

    VALUE
    ----------------------------------------------------------------
    ,.

    If I show a decimal number, I get a comma as decimal separator
    SQL > select 10/100 double;

    10/100
    ----------
    1

    But if I use a decimal separator in the SELECT clause, I get:

    SQL > select 100 * 1.1 double;

    100 * 1 1
    ---------- ----------
    1 100

    It does not work. But the use of a period as the decimal separator works:

    SQL > select 1.1 * 100 double;

    1.1 * 100
    ----------
    110

    Maybe it's something that I never had to deal with before, but I thought that the number format applied to results of sql, as well as the numbers you have used sql clauses.

    Kind regards

    Nestor Boscan

    Hi, Nestor,

    user594312 wrote:
    ... I thought that the number format applied to results of sql, as well as the numbers you have used sql clauses.

    No.; it applies to the results and it can affect implicit conversions, but it does not apply to the SQL code.
    The period (or dot, '.') is the decimal separator in literals always digital. There is no way to change this.

    Think how confusing it would be if it applied to the SQL code. For example:

    WHERE   num_col  IN (1,2)
    

    We compare num_col values 1 or 2? He comes in, what happens if we wanted to do the opposite?

    If you really want to use the comma as the decimal separator, you may have to use strings, not numbers, and it could be much less effective.
    For example:

    SELECT  100 * TO_NUMBER ('1,1')    -- This assumes your NLS settings are correct
    FROM    dual;
    

    Of course, the effectiveness will not be a problem when you select 1 row of double.

  • Pivot control, can the IN clause be dynamic instead of hard-coded values?

    I want to have a number of statements that use the PIVOT command can run dynamically without having to hardcode the values I want to be selected within the 'IN' of sql clause. Here's a simple example.

    REGION_ID COLUMNS SALES_MONTH NUM_SALES

    1 02/01/2010 12
    2010-01-03 1, 11
    1 04/01/2010 10
    02/01/2010 2, 22
    03/01/2010 2, 21
    2 04/01/2010 20

    The PIVOT command, I used is the following:

    Select * from
    (select * from sales)
    PIVOT
    (
    Sum (num_sales)
    for columns sales_month in (February 1, 2010", March 1, 2010", 1 April 2010 "))

    This works very well for now, but as new months are created, I don't want to have to redo all my sql monthly statements. Any suggestions on how I can do this?

    No, unless you use swivel XML:

    select  *
      from  (
             select  job,
                     deptno,
                     sal
               from  emp
            ) pivot xml(sum(sal) for job in (select distinct job from emp))
    /
    
        DEPTNO JOB_XML
    ---------- ------------------------------------------------------------
            10 ANALYSTCLERK1300MANAGER2450PR
               ESIDENT5000SALESMAN
    
            20 ANALYST6000CLERK1900<
               /item>MANAGER2975PRESIDENTSALESMAN
    
            30 ANALYSTCLERK950MANAGER2850PRE
               SIDENTSALESMAN5600
    
    SQL> 
    

    However, if you want it to "format" you still need to know the number of columns returned:

    with t as (
               select * from (
                              select  job,
                                      deptno,
                                      sal
                                from  emp
                            ) pivot xml(sum(sal) for job in (select distinct job from emp))
              )
    select  deptno,
            extractvalue(job_xml,'/PivotSet/item[1]/column[2]') job1,
            extractvalue(job_xml,'/PivotSet/item[2]/column[2]') job2,
            extractvalue(job_xml,'/PivotSet/item[3]/column[2]') job3,
            extractvalue(job_xml,'/PivotSet/item[4]/column[2]') job4,
            extractvalue(job_xml,'/PivotSet/item[5]/column[2]') job5
      from  t
    /
    
        DEPTNO JOB1       JOB2       JOB3       JOB4       JOB5
    ---------- ---------- ---------- ---------- ---------- ----------
            10            1300       2450       5000
            20 6000       1900       2975
            30            950        2850                  5600
    
    SQL> 
    

    SY.

  • SQL update does not

    Hello

    I'm trying to update my database with the following code, but although the code runs without a doubt because he can't seem to echo on the line before the update, the database is not updated.

    If ($totalRows_rsportsale > '0') {}
    $_POST ['dpaid'] = 1;
    $_POST ['listedby'] = $row_rsportid ["listedid"];
    echo ' dpaid is: '. $_POST ['dpaid']. ' < br / > ';
    echo ' listedby is: '. $_POST ['listedby"]. ' < br / > ';
    $updateSQL = sprintf ("UPDATE detailstable SET dpaid = WHERE listedby %s is %s",
    GetSQLValueString ($_POST ['listedby'], "int").
    GetSQLValueString ($_POST ['dpaid'], "int"));

    @mysql_select_db ($database_connUpdate, $connUpdate);
    $Result1 = mysql_query ($updateSQL, $connUpdate) or die (mysql_error ());
    }

    I want to update the database values actually echo right before the update script, so the values are correct for dpaid and listedby, I entered the ILO code was updated in the SQL myphp admin and that updates the database. The connection to the database connUpdate is correct. The two fields are of type "int" in the database and are not primary or unique keys. Any suggestions as to why this update does not work would be very appreciated.

    Thank you in advance.

    No, I don't mean the order of SQL clauses, I mean the order of the two settings that you use.

    $updateSQL = sprintf ("UPDATE detailstable SET dpaid = WHERE listedby %s is %s",
    GetSQLValueString ($_POST ['listedby'], "int").
    GetSQLValueString ($_POST ['dpaid'], "int"));

    As I said, I don't know PHP or sprintf command, but I guess that it replaces the parameters (%s) in the order that they appear. Your (listedby and dpaid) SQL statement parameters are in reverse order. Try to change them.

    $updateSQL = sprintf ("UPDATE detailstable SET dpaid = WHERE listedby %s is %s",
    GetSQLValueString ($_POST ['dpaid'], "int")).

    GetSQLValueString ($_POST ['listedby'], "int");

  • Clause of update with a nested select statement, and a weird error

    Hi all!

    I am trying to execute the following SQL clause:

    setting a day of f_kontakti kon set ikaluokka =
    (
    Select ikal of
    (
    Select kontakt_ik, ikaluokka_gen(1,ai2.pvm,ai.pvm) as ikal
    of f_kontakti k
    Join the a on (k.asiakas_ik = a.asiakas_ik) d_asiakas
    Join d_aika HERE on (a.synt_aika_ik = ai .aika_ik)
    Join d_aika ai2 on (k.aika_ik = ai2.aika_ik)
    where k.kontakt_ik = kon.kontakt_ik
    ) salt
    )

    It works very well on our test database (10.2.0.1.0), but when I try to run it on our production database (10.2.0.4.0), it gives the following error:
    ORA-00904: "KON". "" KONTAKT_IK ": invalid identifier

    The nested select works fine when I run it separately (without where clause of course, because then it does not really anywhere point) on two databases, but for some reason, the full update only fails on the production system. Any ideas on what could cause this?

    Kind regards
    Erik

    You can run it without selecting it nesting.

    Like this

    update f_kontakti kon
    set ikaluokka=
     (
      select ikaluokka_gen(1,ai2.pvm,ai.pvm) as ikal
      from f_kontakti k
      join d_asiakas a on (k.asiakas_ik=a.asiakas_ik)
      join d_aika ai on (a.synt_aika_ik=ai.aika_ik)
      join d_aika ai2 on (k.aika_ik=ai2.aika_ik)
      where k.kontakt_ik=kon.kontakt_ik
    );
    

    or even shorter

    update f_kontakti kon
    set ikaluokka=
     (
      select ikaluokka_gen(1,ai2.pvm,ai.pvm) as ikal
      from d_asiakas a on (kon.asiakas_ik=a.asiakas_ik)
      join d_aika ai on (a.synt_aika_ik=ai.aika_ik)
      join d_aika ai2 on (kon.aika_ik=ai2.aika_ik)
      );
    
  • First value in ORDER MIN different BY

    Hello

    According to the docu NLS_SORT must determine the order of sort ORDER BY and MIN/MAX

    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production

    SELECT *.
    OF nls_session_parameters
    Setting WHERE = "NLS_SORT.
    OR a parameter = "NLS_COMP;

    VALUE OF THE PARAMETER
    ----------- -------
    NLS_SORT GERMAN
    BINARY NLS_COMP

    I therefore expect that I get the same first / min and last/max values of the following

    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production

    WITH testdata as)
    SELECT 'A' double UNION ALL c
    SELECT 'B' c IN double UNION ALL
    SELECT '0' c TO double UNION ALL
    SELECT '1' c double UNION ALL
    SELECT FROM c '2' double
    )
    SELECT MAX (c)
    MIN (c)
    OF testdata.

    MAX (C) MIN (C)
    ------ ------
    B 0

    WITH testdata as)
    SELECT 'A' double UNION ALL c
    SELECT 'B' c IN double UNION ALL
    SELECT '0' c TO double UNION ALL
    SELECT '1' c double UNION ALL
    SELECT FROM c '2' double
    )
    C SELECT
    ASCII (c)
    OF testdata
    ORDER BY c;

    C ASCII (C)
    - ----------
    A 65
    B 66
    0 48
    1 49
    2 50

    So I read on the sort

    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production

    ALTER SESSION SET NLS_SORT = "BINARY";

    C ASCII (C)
    - ----------
    0 48
    1 49
    2 50
    A 65

    B 66

    Now, I get the expected results, but I can't always explain why a linguistic sort order letters before numbers and why it's different to ORDER BY and MAX/MIN.

    Concerning

    Marcus

    According to the docu NLS_SORT must determine the order of sort ORDER BY and MIN/MAX

    OK, but you overlooked that part:

    Accurate operators and the query clauses that obey to the NLS_SORT parameter depends on the value of the NLS_COMP parameter. If a clause or an operator does not comply to the NLS_SORT value, as determined by NLS_COMP , the collation used is BINARY .

    In your example, MIN and MAX always use BINARY collation, unless NLS_SORT is set to a specific language and NLS_COMP is LINGUISTICS.

    On the contrary, ORDER BY, always obeys the NLS_SORT setting regardless of the NLS_COMP parameter.

    This summarizes what operator and SQL clause obeys what parameter:

    Linguistic sorting and string search

Maybe you are looking for

  • imessages will not stick when you restart.

    Whenever I have a message on my Mac to my friend the text disappears once I left iMessage. If I send a text from my iphone for me on the mac is the same. I ' ts gone the next time I open IMessages. I use El Capitan 10.11.6. The problem started after

  • Can satellite M65-S9092 - I put the wireless network card?

    Hello Can I put my card Intel pro 2200BG on Satellite M65-S9092 wireless network so that it is no longer compatible with Windows 7? The Intel Pro 2200BG is no longer supported by Intel as it was abandoned and so they have not issued a new driver so t

  • Reinstalled windows and can not activate

    I have laptop model z500. I have just reinstalled windows using a flash drive. But I have a pro version and I need to activate it using my Windows OEM license. How can I do this? Thank you

  • How to detect the relay ON / OFF state with PCI 6221 analog input card

    In order to test if a relay is ON / OFF using my card PCI 6221 DAQ devices and ports of HAVE it.  I conect of the relay contacts to an AO giving 5 v and the other contact to an AI in order to detect the corrent.  In addition to a bridge is necessary

  • No audio device installed

    original title: sounds I got someone to correct on my computer and they cleaned completely. I noticed when I tried to listen to music it says I have no mixer installed. I need to know how to get the sound on my computer. It's saying that I have no ha