Data type query

SQL> select * from roomtype
  2  ;
   RT_CODE RT_DES    RT_RATE
         1 Single         70
         2 Double         80
         3 Suite         100
SQL> select * from room;
    RM_NUM    RM_TYPE
       201          1
       202          1
       203          2
       204          3
SQL> select * from reserve;
   RES_NUM   RES_ROOM RES_CHKIN RES_CHKOU RES_NAME
      1001        201 01-APR-10 03-APR-10 Dobbs
      1002        201 06-APR-10 08-APR-10 Black
      1003        201 09-APR-10 12-APR-10 Dobbs
      1004        201 16-APR-10 18-APR-10 Gregg
      1005        202 02-APR-10 04-APR-10 Jones
      1006        202 06-APR-10 08-APR-10 Giles
      1007        202 13-APR-10 14-APR-10 Mason
      1008        203 06-APR-10 11-APR-10 Ott
      1009        203 12-APR-10 14-APR-10 Smith
      1010        203 16-APR-10 18-APR-10 Jones
      1011        204 01-APR-10 06-APR-10 Wilson
   RES_NUM   RES_ROOM RES_CHKIN RES_CHKOU RES_NAME
      1012        204 09-APR-10 11-APR-10 Clay
      1013        204 11-APR-10 18-APR-10 OlsenI need help to write a query that will list rooms that would be available for a stay with check in on 4/12 and checkout on 4/16.
I was thinking about using a subquery to find the rooms that are not available then select rooms that are not in the list of unavailable rooms returned by the subquery. What do you think and how would that look that??

Hi,
What you suggested is a good way to do it if you need data from tables other than res_room. (For example, if you were only interested in Double rooms, or in a given price range).
Here's one way to do that:
SELECT  rm_num
FROM     room
WHERE     rm_num     NOT IN  (  SELECT  res_room
                      FROM        reserve
                  WHERE   res_checkin  < DATE '2010-04-16'
                        AND     res_checkout > DATE '2010-04-12'
                  AND        res_room     IS NOT NULL     -- See note below
               );Note: NOT IN never returns TRUE if the sub-query includes NULL. It's likely that this is impossible in your case.
If your only need data from the res_romm table (for example, just the room number) then it will usually be faster to do a query like this:
SELECT       res_room
FROM       reserve
GROUP BY  res_room
HAVING       COUNT ( CASE
                  WHEN  res_checkin  < DATE '2010-04-16'
                AND   res_checkout > DATE '2010-04-12'
                THEN  1
            END
          ) = 0
;If you'd like to post CREATE TABLE and INSERT statements for your sample data, then I could test this.
Hi, Warren,
Won't your query say the room is free if it has a reservation entirely within the target range?
For example, what if res_checkin is April 13, and res_checkout is April 14?
The interesting part of this question is: When do two ranges overlap?
It's actually much easier to aswer the converse question: When do two ranges NOT overlap?
They do not overlap if (and only if) one ends before the other begins.
Therefore, they do overlap if both end after the other begins. (The solution above assumes that res_checkin <= res_checkout, and that the target check-in date is less than or equal to the target check-out date.)

Similar Messages

  • Web Services Complex Data Type Query

    Newbie trying to understand how to work with Complex Data
    Type. Came across the following example in the Dev Guide
    What is wrong with Client Code? What am I missing?
    Please help
    Thanks
    Prashanth

    And That's what I did.
    name.cfc is the component that has complex data types
    created.

  • Data type Query??MM Related(Urgent)!!!!!

    I had an filed in Itab,VBELN(10 Char),when I pass this value to a FM,with imprt parameter MKPF-XBLNR(16 Char),its displaying run time exect error.
    I have to pass the vaule Vbeln to XBLNR to fetch the futher data,what shd i do to match the Types.
    More over i had a field in MKPF-LE_VBLEN(10 Char),it can be used but sometimes its doesnot fetch all the data in QAS,where MKPF-XBLNR do,but in DEV some times XBLRN not work but LE_VBELN wokrs??
    So i m confue whcih to be used,correctly.If QAS is seen than XBLNR is accurate,but i think the type matching Prob will be there too.
    Plz help me...?
    Rgds
    vipin

    Talk to your insurer about the problem. The hard drive is considered by Apple to be a user-replaceable part, so replacing it yourself wouldn't void Apple's warranty if the computer were in good working order. For all the insurer will be able to tell, you could already have replaced the original drive before the accident, and that would have been OK with Apple. You may want to offer to replace the drive you're removing with a brand new one to placate the insurer. Silly as it sounds, that wouldn't cost much (well under $100), and would be far preferable to losing all your data if you were compelled by the insurer to give up the internal drive. I think a reasonable insurer will see the logic.
    You are learning why it's essential to maintain an up-to-date backup of all your data on an external drive at all times. If you had one, this would be a non-issue. Take the lesson to heart, and when you get a new computer, back up its hard drive religiously.
    Afterthought: If your computer will be repaired by Apple rather than replaced, offer to pay for a replacement drive as part of the repair if you're allowed to remove the present drive before sending the machine in.
    Message was edited by: eww

  • Error in SQL Query The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query

    hi Experts,
    while running SQL Query i am getting an error as
    The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    T2.LineText
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,T2.LineText
    how to resolve the issue

    Dear Meghanath,
    Please use the following query, Hope your purpose will serve.
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    CAST(T2.LineText as nvarchar (MAX))[LineText]
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry LEFT OUTER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry --where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,CAST(T2.LineText as nvarchar (MAX))
    Regards,
    Amit

  • Error While Creating Date type condition query

    Hi All,
    I am getting following error while creating a multiple condition query.
    ERROR:java.lang.IllegalArgumentException: Unexpected field type for D: java.lang.String
    I am pasting the scrap of the code for review below.
    pls note after removing the condition cond6; it works fine, and cond6 is for date type field.
    for(int j=1;j<7;j++){                          
    fd[j] =trd.getFieldDescriptor(arrayHeaderFieldNames[j]);
    BasisFieldType bft1 =  fd[j].getFieldType();
    if (bft1 == BasisFieldType.C) {
      filterOperator[j] = RelationalOperatorType.CONTAINS;       }
    else{
      filterOperator[j] = RelationalOperatorType.EQUALS;
    order[j] =queryFactory.createSortOrder(fd[j],true);
    cond1 =queryFactory.createCondition(fd[1], filterOperator[1], values[0]);
    cond2 =queryFactory.createCondition(fd[2], filterOperator[2], values[1]);
    cond3 =queryFactory.createCondition(fd[3], filterOperator[3], values[2]);
    cond4 =queryFactory.createCondition(fd[4], filterOperator[4], values[3]);
    cond5 =queryFactory.createCondition(fd[5], filterOperator[5], values[4]);
    cond6 =queryFactory.createCondition(fd[6], filterOperator[6], values[5]);
    Condition cond = queryFactory.createCondition(new Condition[]{cond1,cond2,cond3,cond4,cond5,cond6},LogicalOperatorType.AND);
    Please Help!
    Thanks n regards,
    Kapoorchand.

    Hi,
    well that problem is a long time back -. I only have in mind that the date I had to transfer to the quesry was in a "strange" format. Have a lock into the documentation for the date field - your date field is not recognised as a date field from the quesry engine and so this fails - but unfortunately I have no idea at the moment how I fixed it last time - how I converted my date field......
    Sorry, thast I can not give you the real point - but I will have a lock into the old code - hopefully I find it soon.
    Regards,
    Oliver

  • Problem to get ResultSet when it is used a Date type in the query condition

    hello ,
    I having a bit of nightmare getting a ResultSet how result of one simple Query for a table when the condition WHERE involve a Date type.
    To change the String value in a date to use in the query condition, I tried both:
    String strDate = "dd/mm/yyyy";
    (1.) java.sql.Date sqlDate = new java.sql.Date(strDate.getTime() )
    (2.) SimpleDateFormat formatter = new SimpleDateFormat(strDate) ; sqlDate = formatter.parse(strDate);
    and finally I use this code to get the ResultSet:
    sql = "SELECT * FROM myTable Where (idCli = " + cd_Cli + " And dateReg = " + sqlDate + ")";
    statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    resultSet = statement.executeQuery(sql);
    boolean ok = resultSet.last();
    totNumberOfRegistration = resultSet.getRow();
    But In both the cases I get a empty resultSet.
    I shoul like if someone would look my code to say me where it is the mistake...
    thank you
    tonyMrsangelo
    P.S. I tryed using PrepareStatement too to get the ResultSet, but in that case I couldn't use the ResultSet because executing the statement resultSet.last() I get the error: "Result set type is TYPE_FORWARD_ONLY"

    In a database like Oracle, you need to use a function like TO_DATE; other databases may have something similar.
    However, the proper way to do this is to use a PreparedStatement. Then you can say
    PreparedStatement ps = conn.prepareStatement("update SOMETABLE set SOME_DATE=? where SOME_ID=?");
    ps.setDate(1, new java.sql.Date(someJavaUtilDate.getTime()));
    ps.setInt(2, theId);
    ps.executeUpdate();

  • Problem with a query with a BLOB data type

    Hi i've a problem with this query in 11g. R1
    SELECT
          LOGTIMESTAMP,
          LOGTIMEMILLIS,
          MSGID,
          XMLTYPE(MESSAGEBODY, nls_charset_id('AL32UTF8')).getClobVal()  as LLamada
    FROM
        vordel.AUDIT_MESSAGE_PAYLOAD,
        vordel.AUDIT_LOG_POINTS
    WHERE
        AUDIT_LOG_POINTS.LOGPOINTSPK = AUDIT_MESSAGE_PAYLOAD.MP_LOGPOINTSPK AND
        LOGTIMESTAMP between TO_TIMESTAMP('03-12-2011 00:00','DD-MM-YYYY HH24:MI') and  TO_TIMESTAMP('03-12-2011 12:00','DD-MM-YYYY HH24:MI')
         and filtertype = 'LogMessagePayloadFilter'
      and filtername like 'Log Llamada%'MESSAGEBODY: data type of the Column is BLOB
    throw this error after execute the query
    Error:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00200: could not convert from encoding UTF-8 to UCS2
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 283
    ORA-06512: at line 1

    Could you check the BLOB really contains UTF-8 encoded XML?
    What's your database character set?The BLOB contains UTF-8 Encoded
    and the database where i am connectes have AL32UTF8 character set, but my internal instance have "AMERICAN_AMERICA.WE8ISO8859P1"
    that is a problem?
    How could I change the character set of the oracle local client to the character set of the remote oracle data base?

  • Data Type enhancement Query.

    Hi All ,
    I have a query regarding Data type enhancement . We can create a Data Type enhancement based on a standrd Data Type and give a new name to this DataTypeEnhancement (DTE_Test). This is clear . My question is how do we actually use this newly created DataTypeEnhancement .
    In my case I do not want to change the Orignal Standard Objects.  I want to create Objects in a separate Custom SWCV . Can we create a new DataType / MessageType based on this DataTypeEnhancement and Use it. 
    Thanks
    Nilesh.

    Nilesh,
    Check this document 3.3 and its usage:
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c0bb5687-00b2-2a10-ed8f-c9af69942e5d?overridelayout=true
    Regards,
    ---Satish

  • Query regarding the data type for fetcing records from multiple ODS tables

    hey guys;
    i have a query regarding the data type for fetcing records from multiple ODS tables.
    if i have 2 table with a same column name then in the datatype under parent row node i cant add 2 nodes with the same name.
    can any one help with some suggestion.

    Hi Mudit,
    One option would be to go as mentioned by Padamja , prefxing the table name to the column name or another would be to use the AS keyoword in your SQL statement.
    AS is used to rename the column name when data is being selected from your DB.
    So, the query  Select ename as empname from emptable will return the data with column name as empname.
    Regards,
    Bhavesh

  • How to query / list table name with certain data type?

    Hi all spatials,
    Sorry for the dumb question. I need to make a query that list all table name that contain certain data type, eg. SDO_georaster. How to do this ?
    Many thanks in advance
    damon

    Skip it. I figured it : using USER_TAB_COLUMNS will definitely help.
    Cheers
    damon

  • Query Parameter Data Type error betwee IE6 and IE7

    Hello all.
    This is a strange one. Using MII v12. When setting parameters for a SQL query from Javascript, the query executes properly on IE7 but generates errors on IE6. The errors are JDBC errors having to do with "Conversion failed when converting datetime from character string." and "Error converting data type varchar to numeric." I don't get any browser errors, only Java errors and NetWeaver log entries.
    What is the source of this data typing error?

    Hi, Sparks.
    Actually, IE was always an anomaly when it came to proper typing of objects in Javascript, so it let you get away with things that really shouldn't work.
    In general, you should use the Number Javascript type for number properties (e.g. setRowCount(), setXAxisMinRange(), etc) and strings for just about everything else.  If I recall, Javascript will handle most of the type conversions to a String property, but not necessarily to a Number property.
    You can use the parseInt() and parseFloat() methods to convert from strings to numbers in Javascript.
    In general, it's a good practice to be "type aware" in your Javascript code anyway, and this will ensure that it runs in other browsers and future browsers.
    Rick

  • Dates in BEx query coming into designer as a dimension with Char data type

    This must be an old issue with a well documented work around ...   but alas i can find it !
    When i build a universe over a BEx query with dates the universe designer builds them as Dimensions of CHAR type not DATE.  Therefore all WebI date functionality fails ..  eg sorting, automatic time hierarchies etc.
    What is the workaround ?
    Andrew Fox

    Is the data source an InfoSet or an InfoCube?  It appears the date type object has not been implemented yet for Infosets.  Here's SAP Note 1370410:
    Symptom
    Infoset date type objects (DATS type) are mapped as Character types in a universe based on a SAP BEX Query.
    Prompts related to the Date field variables are coming as List of values instead of Calendar in WebIntelligence.
    Reproducing the Issue
    Create a BusinessOjects universe on a Super Query which is based on a multiprovider containing an Infoset or
    Create a BEx superquery directly on Infoset.
    BusinessObjects Enterprise XI 3.1
    SAP Integrated Solutions Kit XI 3.1
    Cause
    This behaviour has been considered as an enhancement request and tracked under ADAPT01229917.
    Resolution
    This enhancement request is scheduled to be addressed in Service Pack 3 (SP3) for BusinessObjects Enterprise XI 3.1 due approximately April 2010.
    I did try a BEx query that uses an InfoCUBE as a source and the objects are coming into the universe correctly as dates.

  • URL data type in CAML Query with Client side object model

    hi,
    How do I write a CAML query to filter list items based on the URL field using it's Description?
    Same with REST API. How do I construct a REST query so that filter list items based on the URL data type using it's Description.

    Hi Cooltechie,
    Thanks for posting your query, Below are the example that you can use in your CAML query
    <Where><Eq><FieldRef Name="FileRef"/><Value Type="Url">sites/SiteCollection/SubSite/Site Documents/Excel Report.xls</Value></Eq></Where>
    Note: Do not include the server name or beginning /.
    The following examples assuming you have a list or library setup with a URL column named "My Document".
    The link is to a document that is hosted on the sharepoint server (do not need server name):
    <Where><Eq><FieldRef Name="My_x0020_Document"/><Value Type="URL">/sites/subsite/Site%20Documents/Excel%20Report.xls</Value></Eq></Where>
    The link is an absolute URL to something not on the server... for example http://www.google.com:
    <Where><Eq><FieldRef Name="My_x0020_Document"/><Value Type="URL">http://www.google.com</Value></Eq></Where>
    I hope this is helpful to you, mark it as Helpful.
    If this works, Please mark it as Answered.
    Regards,
    Dharmendra Singh (MCPD-EA | MCTS)
    Blog : http://sharepoint-community.net/profile/DharmendraSingh

  • SQL Query using DATS data type

    Hello people,
    I have a table 'TableA' with a column 'xpto' that has DATS data type.
    A lot of lines in this table has this field empty.
    I have to create a SQL query to select those lines with this field not empty.
    Select * from TableA
    where xpto is not null
    It does not work.... The result is all the lines in the table.
    What is wrong?
    Thanks!

    Easiest way to do this is :
    constants l_xpto   type tableA-xpto  value is initial
    Select * from TableA
    where xpto ne l_xpto.
    You can see the NULL/NOT NULL settings for the column through SE11
    Utilities -> Database Object -> Display.
    I tend to set the "Initial Value" flag when adding columns to tables, which creates the database column as NOT NULL with a default value (whatever SAP considers the initial value for that datatype). I think SAP does this by default, but I've had issues where it hasn't so I do this to ensure consistency
    Chris Bain

  • How to query on date data type.

    Hi,
    I have a column RCVDDT which is DATE data type. Using this I need to query the records where RCVDDT <=(SYSDATETIME - 2 Hours), Need all the records which are 2 hours old or more.
    I am using this query:
    select * from tablename where RCVDDT <= to_date((sysdate - INTERVAL '2' hour),'yyyy-mm-dd HH24:MI:SS') order by RCVDDT desc
    Thanks in Advance,
    -Sree

    A very common mistake is to apply TO_DATE() against sysdate. Sysdate is a date already and applying TO_DATE() to it can really muck up your results. Besides your syntax for TO_DATE(), even if appropriate, is not correct because it relied on default date format, which will also lead you to grief.
    select * from tablename where RCVDDT <= sysdate -2/24;

Maybe you are looking for

  • ASA 5505 Failure replaced and need to move the license key?

    Can someone point me in the right direction? My ASA 5505 died due to a power surge and I swapped it with a spare. I had Security Plus and a 50 user license and need to move the license keys from the failed ASA 5505 to the new one. I kept both my emai

  • AI crashes when I try to open a file or make a new one. Any advice please?

    I'm using a laptop and windows.  AI starts up ok but I can't actually create anything before it shuts itself down.  Any advice please?

  • Default outgoing email address is wrong, how do I change it ?

    I've been using Thunderbird successfully for several years with 6 different email accounts - 1 gmail account, 2 yahoo accounts, and 3 accounts on another domain. Recently I added a new gmail account for a project I'm working on. Now, the default emai

  • Dynamic PDF's for Mobile Devices

    I have been converting my company's forms to dynamic pdf format using ES4 to facilitate completion and submission by our highly dispersed workforce.  These forms are unfortunately not accessible on the mobile devices our field employees typically use

  • Inputs for running /SAPAPO/SDORDER_DEL report

    Hello, We want to run /SAPAPO/SDORDER_DEL report to delete unnecessary Sales orders in the APO system. Before while executing this report I would like to be clear on 2 points: 1. Three tabs with various fields came up after executing this report: