Using a date variable in a where clause

Hi,
I need to run a select query which contains the following
e.g
String query = SELECT APP_DATE, APP_TIME, APP_TYPE, a.CUST_NO
FROM APPOINTMENTS a, PATIENT_DETAILS p
WHERE APP_DATE = " + appDate + " and p.CUST_NO = a.CUST_NO
appData is a java.sql.Date format and contain the date i want to find. The error i get is "Operator = doesn't apply to the types <DATE> and <INT>"
I have also read somewhere that this would return the date at midnight and therefore would not match, how can i fix this. I am using JDataStore for development.
Thanks
Rudy

you want something like this
SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd");
String sql = "SELECT * FROM Table WHERE appDate='" + df.format(appDate) + "';";     
Or if you used prepared statements, you could pass the java.sql.Date to it without the need to convert.

Similar Messages

  • How to use a lexical variable in a WHERE clause and as a function argument.

    Hello,
    My report has a lexical variable which has values like 'and id in (1,3,4)'. I want to use this variable in two separate queries. In the first, it is used in the WHERE clause, something like:
    .. where date is not null &var;
    In the second query, the variable is used in a function call, something like:
    select * from table (my_function(&var));
    The trouble is that the first query works when the value of the variable is unquoted, but for the second query the value should be quoted.
    Does anyone have an idea how I could solve this problem?
    Thanks in advance,
    Frans
    Message was edited by:
    fransie

    http://tkyte.blogspot.com/2006/06/varying-in-lists.html
    Presents many options.

  • NVL with host variables in a where clause

    Does anyone know if using a host variable in a WHERE clause with
    the NVL function will actually work if the host variable is null
    without using the indicator variable too?
    In other words if the variable ":new_prmy_numb" which was
    selected previously is actually null, will the NVL know that it
    is null without the indicator variable being listed also? The
    person at our company who has this in their code says it works
    and the rest of us don't see how.
    Example:
    SELECT recd_a_id from ADDR
    WHERE
    NVL(prmy_numb,' ') = NVL(:new_prmy_numb,' ')

    well firstly have you tried it to see if it works? That would seems to be a rather obvious step, I would imagine.
    Anyway, I don't see anything wrong with the code, except that it might be optimized better ...
    SELECT recd_a_id from ADDR
    WHERE
    (prmy_numb = :new_prmy_numb
    or (:new_prmy_numb is null and prmy_numb is null))
    ... might stand more chance of using an index on the column prmy_numb

  • How to use a bind variable in an IN clause

    I am trying to use a bind variable in an IN clause where the column is a varchar2 type. Something like:
    select *
    from test
    where test_column in (:bindVariable)I have tried assigning the bind variable comma separated strings (eg. test,test,test) and comma separated strings with quotes (eg. 'test','test','test'). Neither of these work. Does anyone know the correct way to do this?
    Thanks in advance.

    http://tkyte.blogspot.com/2006/06/varying-in-lists.html
    Presents many options.

  • Want to use presentation date variable in Advance SQL filter option

    Hi,
    I want to use presentation date variable in Advance SQL filter option.....I am getting the below error.
    SQL in Advance SQL filter ----
    "Fact Status Details"."Load Date" =
    (select min(Cast("D Time"."Business Date" as char))-1
    from "D Time" where "D Time"."Operational Month Sk" =
    (select "D Time"."Operational Month Sk" from "D Time" where date '@{Date1}'=cast("D Time"."Business Date" As char)))
    Error ---
    Error getting drill information: SELECT "Fact Status Details"."Load Date" saw_0 FROM "Pre RFAI Sales" WHERE "Fact Status Details"."Load Date" = (select min(Cast("D Time"."Business Date" as char))-1 from "D Time" where "D Time"."Operational Month Sk" = (select "D Time"."Operational Month Sk" from "D Time" where date '@{Date1}'=cast("D Time"."Business Date" As char)))
    Error Details
    Error Codes: YQCO4T56:OPR4ONWY:U9IM8TAC:OI2DL65P
    Odbc driver returned an error (SQLExecDirectW).
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 27002] Near <select>: Syntax error [nQSError: 26012] . (HY000)
    SQL Issued: {call NQSGetLevelDrillability('SELECT "Fact Status Details"."Load Date" saw_0 FROM "Pre RFAI Sales" WHERE "Fact Status Details"."Load Date" = (select min(Cast("D Time"."Business Date" as char))-1 from "D Time" where "D Time"."Operational Month Sk" = (select "D Time"."Operational Month Sk" from "D Time" where date ''@{Date1}''=cast("D Time"."Business Date" As char)))')}
    Load Date format ---YYYYMMDD
    Please advise...i need to fix this issue urgently.

    Thanks for your reply.
    Could you please help me with the correct code...i tried to correct it....
    "Fact Status Details"."Load Date" =
    (select Cast(min("D Time"."Business Date" )-1 as char)
    from "D Time" where "D Time"."Operational Month Sk" =
    (select "D Time"."Operational Month Sk" from "D Time" where Date'@{Date1}'=cast("D Time"."Business Date" As char)))
    Please let me know if i am wrong..this code is also not working.

  • Using a Dimension/ Measure in a Where clause of Another Dimension/ Measure in IDT

    Hi All
    I am building a Universe using Information Design Tool. In the Business Layer, I need to use a created Business Layer Dimension (not Tables) in a Where clause of another dimension as follow:
    Dimension: "Current Week No"
         SELECT
              budgets.dbo.Calenderweeks.WeekNo
         WHERE
              budgets.dbo.Calenderweeks.EndDate = convert(SMALLDATETIME, fn CURDATE()})  
    Dimension: "Last Week No"
         SELECT
              budgets.dbo.Calenderweeks.WeekNo
         WHERE
              budget.dbo.Calenderweeks  .WeekNo = @Select(Dimension\Current Week No) - 1
    The first dimension is working well. However, the "Last Week No" shows NOTHING (I do not get any value)
    Anyone can explain why I am not get any value from the second dimension, and how I can use a Dimension/ Measure in a Where clause of another Dimension/ Measure ?
    Thanks

    Short answer:
    Beware of object WHERE clauses. They are rarely (I'd almost say never) the solution to the problem you're trying to solve.
    Long answer:
    It doesn't work because you are inadvertently filtering the same value twice in two incompatible ways in the same SQL statement.  Both objects SELECT the same column in the database.  The first object uses a WHERE clause to set it to the current week.  The second object attempts to use a WHERE clause to set it to the previous week, but does so by selecting the first object, so you end up with both objects in your data provider.
    Remember that BO is going to place all the objects in your data provider in the same SQL (except of course where your context definition has ensured otherwise.), so you have two WHERE clauses in your generated SQL which attempt to find a line equal both the current week and the previous week... and returns, naturally, no results.
    Rewrite it with a derived table (as explained in the response above) and you'll get what you want.

  • How to select data from a table using a date field in the where condition?

    How to select data from a table using a date field in the where condition?
    For eg:
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
                                                      and bdatu = '31129999'.
    thanks.

    Hi Ramesh,
    Specify the date format as YYYYMMDD in where condition.
    Dates are internally stored in SAP as YYYYMMDD only.
    Change your date format in WHERE condition as follows.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and bdatu = <b>'99991231'.</b>
    I doubt check your data base table EQUK on this date for the existince of data.
    Otherwise, just change the conidition on BDATU like below to see all entries prior to this date.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and <b> bdatu <= '99991231'.</b>
    Thanks,
    Vinay
    Thanks,
    Vinay

  • How to use an UNIX shell variable in sql where clause

    Hi ,
    In my shell script first I get the Date and time from the system into the shell variable.At the end of the shell script I need to run a sql script in which I want to use the variable value in the where clause . Is there any way we can use a shell variable value in SQl script ?. Any help is greatly appriciated .
    Thanks in advance,
    Sampath

    Try the following
    In Unix
    SQLPLUS <username>/<password> @MyScript.sql <UNIX_Variable>
    In SQL*Plus
    Reference the variable as &1
    select *
    from MyTable
    where MyDate = to_date('&1','<date_format>');

  • Using bind variable in dynamic where clause and concatenate with query

    Hi,
    In my procedure i am framing where clause dynamically with bind variable,When i am concatenate this with my sql query for REF CURSOR i got sql command not properly ended exception.
    Is it possible to pass values to the bind variable through the dynamic variable/value?
    Please advise
    Thanks in advance
    Siva
    IF in_applicationId IS NOT NULL THEN
              optional_where := optional_where || ' AND a.APPLICATION_ID like '||':e%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id'||',in_applicationId';
         END IF;
    My query is like this
    open Out_Main FOR SelectQuery USING optional_using

    Thanks for reply,
    In my procedure, i suppose to frame the where clause with bind dynamically according to the input parameters. so that i am framing the values of the bind variables also dynamically like this,
    Please advise...
    IF in_assignedAppFlag IS NOT NULL THEN
              IF in_assignedAppFlag = 'Y' THEN
                   optional_where := optional_where || ' AND b.ASSIGNED_TO = :b' ;
              optional_using := ' in_appFuncGroup'||',in_currentUserID';          
              ELSe
                   IF in_isSupervisor = 0 THEN
                        optional_where := optional_where || ' AND (b.ASSIGNED_TO = :b'||' OR b.ASSIGNED_TO = ''-1'' OR b.ASSIGNED_TO IS NULL)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID';
                   END IF;
              END IF;
         ELSE
              IF in_isSupervisor = 0 THEN
                   optional_where := optional_where || ' AND (b.ASSIGNED_TO = :b'||' OR b.ASSIGNED_TO = ''-1'' OR b.ASSIGNED_TO IS NULL)';
                   optional_using := ' in_appFuncGroup'||',in_currentUserID';
              END IF;
         END IF;
         IF in_appFuncGroup IS NOT NULL THEN
              optional_where := optional_where || ' AND e.APP_FUNC_GROUP= :c';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup';
         END IF;
         IF in_queue_id IS NOT NULL THEN
              optional_where := optional_where || ' AND b.QUEUE_ID = :d';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id';
         END IF;
         IF in_applicationId IS NOT NULL THEN
              optional_where := optional_where || ' AND a.APPLICATION_ID like '||':e%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id'||',in_applicationId';
         END IF;
         IF in_sourceCode IS NOT NULL THEN
              optional_where := optional_where || ' AND e.APP_SOURCE_CODE like '||':f%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode';
         END IF;
         IF in_logo IS NOT NULL THEN
              optional_where := optional_where || ' AND appProds.PRODUCT_TYPE like '||':g%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo';
         END IF;
         IF in_firstName IS NOT NULL THEN
              optional_where := optional_where || ' AND upper(a.FIRST_NAME) like upper(:h%)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName';
         END IF;
         IF in_surName IS NOT NULL THEN
              optional_where := optional_where || ' AND upper(a.SURNAME) like upper(:i%)';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName'||',in_surName';
         END IF;
         IF in_retreival_id IS NOT NULL THEN
              optional_where := optional_where || ' AND e.RETREIVAL_ID like :j%';
              optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
              ||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName'||',in_surName'||',in_retreival_id';
         END IF;

  • How to bind a VO :variable in a WHERE clause to a page parameter

    Hello,
    I have a VO. This VO has a variable :v in the WHERE clause of the query.
    This VO is used by different UI components in a page (a table, a tree). The page already has a parameter defined in his properties #{viewScope.myparam}
    What I want is to bind :v to the #{viewScope.myparam}, so that I can specify :v from a parameter in the URL, so that the table immeditaly shows the proper results.
    Is there a way to Bind :v to #{viewScope.myparam} directly in the VO definition in the model project? (It seems it is not possilble)
    The other alternative is to use ExecuteWithParams, but in this case I do not know how to perform the query without user actions in a trasparent way. I dont want to associate execute operations to UI components.
    thanks

    Hi,
    +Is there a way to Bind :v to #{viewScope.myparam} directly in the VO definition in the model project? (It seems it is not possilble)+
    No, this can't be done
    The other alternative is to use ExecuteWithParams, but in this case I do not know how to perform the query without user actions in a trasparent way. I dont want to associate execute operations to UI components.
    If you are within a bounded task flow or in an unbounded task flow that does not have this page as its first view (home page) then you can drag and drop executeWithParams as a method call activity. The attribute then should be saved in the pageFlowScope (not the viewScope).
    In addition I would use a ViewCriteria instead of "hard wiring" the bind variable to the VO definition. You can then - in the AM data model section - associate the View Criteria with the VO instance yo use in the UI
    Frank

  • Using a report value for a where clause in other report

    Hi All,
    i'm getting kinda nuts here. I created a page with three reports.
    First report show the name of the user who logged in with his/her whole name. Second report shows the year, week, begin/end date of the week for the user in the first report. The third report show the hours the user worked in the week selected in the second report.
    The link between first and second report is on column report. Somehow i managed it to work with second_report.mdw_code = :P3_ACRONIEM. I have no idea were this P3_ACRONIEM item is coming from, while i have no items in my page whatsoever. Now i need to link the second report to the third report. I have to use the second_report.mdw_code, second_report.year and second_report.week but i have no idea how to link these together. Any idea's? (Like making items, but then i have no idea how to link that item to the value in the second report). Please help.
    Kind regards,
    Dave
    The link between the first and the second i could get it to work with :P3_ACRONIEM. I have no idea where this ITEM is coming from, because i have no items in my page (and it's the only page in the application). Then

    Hi Dave,
    If I understand you correctly, you have a one report that lists users, a second report that lists dates and a final report that shows hours worked?
    If so, you may find it easiest to have hidden fields on your page and base the second and third reports on these using appropriate WHERE clauses. (I generally put hidden fields in a region in the "After Header" position)
    So, if the first report contains a USER_ID field, have a hidden field called P1_USER_ID. The link on the first report will branch back to the same page and set the value of P1_USER_ID to #USER_ID# The second report can then use WHERE USER_ID = :P1_USER_ID. When the page reloads, the second report redisplays and is filtered to show only those records relating to the selected USER_ID in the first report.
    To extend this, if the second report contains WEEK_NUMBER, it should have a link that branches back to the same page and sets a hidden P1_WEEK_NUMBER field with #WEEK_NUMBER#. The third report should when have WHERE WEEK_NUMBER = :P1_WEEK_NUMBER AND USER_ID = :P1_USER_ID. You can, if need be, have and set more than one hidden field during each link.
    Regards
    Andy

  • When formatting a date field in a where clause the template put dot instead of comma

    Hello to Headstart Workers !
    In a query find block the template construct a where clause, in some cases, and i dont know when the template is formatting a date field putting a dot instead of a comma.
    Ex.: to_date('19-01-2001'.'DD-MM-YYYY')
    Anybody knows why or where the template do this.
    Congratulations
    Nelson

    - We created it using the HS utilities.
    - "nls_numeric_character = ,.".
    - it onky happen when the field date is not the first field in the where clause.
    - i can see the problem just after pressing find button, already in the ls_block in last_query.
    - the find_query works normally but cannot edit any line in ls_block.
    Hope that i had helping
    Regards
    Nelson
    null

  • Variable for entire where clause

    Is it possible to use a variable for the entire where clause in a PL/SQL select statement?
    I have a where clause stored as a string in the database and I want to use that entire string as a variable, but my procedure will not compile because it is missing the relational operator.
    SELECT whereclause FROM clausetable WHERE clause = 'TEST'; will return this string: column1 = 'abc'
    Here's my procedure:
    create or replace
    PROCEDURE TESTWC
    (c_out OUT sys_refcursor )
    AS
    BEGIN
    DECLARE
    v_whereclause VARCHAR2(255);
    BEGIN
    SELECT whereclause
    INTO v_whereclause
    FROM clause_table
    WHERE clause = 'TEST';
    DBMS_OUTPUT.PUT_LINE(v_whereclause);
    OPEN c_test FOR SELECT * FROM dpacsoftware WHERE v_whereclause;
    NULL;
    END;
    END TESTWC;

    Is it possible to use a variable for the entire where clause in a PL/SQL select statement?Unfortunately yes.
    I have a where clause stored as a string in the databaseThis is a really bad idea, like storing the source for half your program in a text file with a bunch of Java or C or FORTRAN code and opening, reading, compiling and linking at run time.
    It is slow, slow, slow as you can expect, and dangerous and insecure, since someone could have put a format C: command in your source file, or something equivalently nasty to a database.

  • Mutating table exception & use of a table column in where clause

    Hello,
    I have a scenario in which I am getting a Mutating table exception in which I have a trigger using which I insert into a second table in case there is an insert in the first table or the one which is associated with the trigger .
    my trigger code has this line which is causing the Mutating table exception :
    BEGIN
    IF INSERTING THEN
    SELECT a,b INTO var_a,var_b
    FROM tableA,tableB,tableC
    WHERE tableC.c = :new:c
    The problem is the tableC reference in my where clause is causing a Mutating table exception , but I don't see any other way in which I can get rid of it cause I need to check if new:c values exists in the table or not , can anybody suggest how I can get rid of the tableC reference in my SQL statement yet be able to check for the value of :new:C in my statement ?

    Hopefully this demonstrates the problem , the bold portion or the where clause is where I am getting flummoxed , I need to be able to compare the new value to a column in table C but if I use tableC reference I get mutating table exception
    create or replace
    trigger myTrigger
    after insert or delete or update on TableC
    referencing old as old new as new
    for each row
    DECLARE val1 number; val2 CHAR(1);
    BEGIN
    IF INSERTING THEN
    SELECT tableA.val1,tableB.val2 INTO val1,val2
    FROM TableA tableA,TableB tableB
    WHERE :new.val1
    AND :new.val1 is not null
    AND tableA.val2 = :new.val2
    AND tableB.val3 = tableA.val3
    AND tableC.val4 = :new.val5
    INSERT INTO TableD (col1 ,
    col2,
    col3,
    col4,
    col5,
    col6,
    col7,
    col8,
    col9)
    VALUES(:new.val1,
    :new.val2,
    :new.val3,
    tableA.val1,
    tableB.val2,
    :new.val4,
    :new.val5,
    :new.val6,
    :new.val7);

  • Date format in a where clause

    Hi Gurus,
    I'd like to filter the data displayed in a report according to the date,we have an agenda for meetings,when I open the meetings report,it should display only the meetings of today,here what I did:
    where meeting_date =
    nvl(to_char(:tday,'dd-mm-yyyy'),to_char(sysdate,'dd-mm-yyyy'))this where clause is put in the query of the region source,
    tday is a date picker to allow the user to change the date if he wants to navigate to other dates (other than today)
    It gives me the error 'ora-01722'
    where I went wrong?
    Putting in mind that the meeting_date column contains meeting time too,what ever the meeting time is,if it is for today it should be displayed.
    Mohammad

    Hi,
    Not sure if this will help but maybe you could try:
    where to_char(meeting_date,'dd-mm-yyyy') =
    nvl(to_char(:tday,'dd-mm-yyyy'),to_char(sysdate,'dd-mm-yyyy'))
    or perhaps this one:
    where to_char(meeting_date,'dd-mm-yyyy') =
    nvl(:tday,to_char(sysdate,'dd-mm-yyyy'))
    Thanks,
    Richard.

Maybe you are looking for

  • ITunes wont open and wont install or update!!  Need help!!

    Everytime I try to open my itunes I get a pop-up saying "QuickTime version 7.0d0 is installed, iTunes requires QuickTime version 7.1.3 or later. Please reinstall iTunes." This message also appears whenever I try to update my itunes or reinstall it. C

  • Classic has a problem and I need help

    I have a 20gb classic that someone have my son. When I plug it in to charge the apple logo comes on and then it shows a file with an exclamation point and also a battery with a small amount of charge with an exclamation point. It also will show do no

  • Need help in installing windows 7 on macbook pro 10.5.2

    Hello friends, yesterday i bought a original copy of windows 7 home basic version. I created a new partition using bootcamp and when I am inserting the new DVD of windows 7..its giving error "Installer disk could not be found" And after few seconds t

  • HP Pro Book 4540s SATA III Support

    Does 4540s support SATA 3 ? optional i mean and is there any models in HP that support SATA 3 ?

  • Unable to make use of Service "Release Supplier Invoice"

    We have recently installed EHP-3. I have been trying to make use of the following service Under Repository Browser --> Package -- > OPS_SE_IVE_XI_PROXY Enterprise Services -- > Server Proxies ---> II_IVE_E_INVOICEREPRELRQ (Double Click) The Service R