Help with, when part of my query

Well, I'm reading from a table that has several fields in there, but I am afraid only about four (subject, extraordinary place, image). I want all of the records returned, unless:
object is equal to birthday or buzz or house or stowt or volunteer
Special is equal to elderhostel1 or elderhostel2 or LewisClark rt66
location is equal to ranch
the picture is blank

If everything above is true, then this record is not returned

There are cases where subject could be people and location is ranch - this record should not be returned due to the location being ranch, although people is not excluded from the scope of the object.

WHERE
("anniversary" <>topic
AND the subject <>"buzz".
AND subject to <>'House '.
AND subject to <>"stowt".
AND subject to <>'volunteer')
OR (special <>'elderhostel1'
AND special <>"elderhostel2".
AND special <>'LewisClark.
AND special <>"rt66")
OR location <>"ranch".
Image <>OR "

Your help is appreciated

ARGH - I found the problem (or at least I think I have)... I keep the DB, so I didn't know that there are empty fields in some of the columns of the object and special columns, once I set that things worked (in my test DB - now I have to apply to my full DB).

Thanks to everyone who tried to help me with this.

Tags: ColdFusion

Similar Questions

  • Help with the part number - paw index screen X230ti

    Can anyone help with the reference number and or the availability of the small 'legs' that sit in the slots on each side of the keyboard on a X230ti? They locate into the slots with the screen and prevent movement when the lid is closed.

    I have the same and among the small beasts broke and the screen tends to rotate when closed.

    Have searched for a parts list but cannot find the "paw" in any list that I found. Thank you

    Here is a picture of the X230t keyboard (and palmrest) framework. You can see the small 'legs' to belong to him.

    I hope someone from Lenovo will tell you how to order this part. EDIT: part number 04W6808.

  • help with ABSORBING BY in my query when negative numbers are involved

    Jin

    I have

    SELECT *.
    FROM my_table
    WHERE age = 5
    ORDER BY DESC photoSmall

    my_table looks like this:

    key | Age | photoSmall
    1-25-2
    2-25-3
    3-25-1
    25 4 - 1

    now, I'm waiting for my results should be classified as follows:

    first record 2 (because it has the highest value 'photoSmall' 3)
    then save 1 (he has the next highest value "photoSmall) 2.
    then record 3 ("photoSmall" being 1)
    Finally save 4 ("photoSmall'-1 being the lowest value of all the...)

    but no!

    It seems that CF is treatment - 1 and 1 as being the same, strange

    do I have to modify my query to:

    SELECT *.
    FROM my_table
    WHERE age = 5
    ORDER BY CFpositive_numbers_are_greater_than_negative_numbers DESC photoSmall = YES?

    any help would be greatly appreciated - thank you very much indeed.

    Quote:
    Posted by: happysailingdude
    photoSmall is a text field
    I use access
    Thanks a lot for your help

    If you store any other numbers, why is not a numeric field?

  • Help with upgrade parts! ThinkCentre M58 7244

    I recently purchased the Lenovo ThinkCentre M58 (7244A 36) computer to desktop PC off newegg, and I want to improve the additional parts. I just want to know the following

    (1.) what type of processors are compatible with it?

    (2.) what type of RAM is compatible with it?

    (3.) what kind of graphics cards are compatible with it?

    Help would be very appreciated. It's the computer, by the way: http://www.newegg.com/Product/Product.aspx?Item=83-108-659&SortField=0&SummaryType=0&Pagesize=10&Pur...


  • Helps with the exclusion of the query items

    I compare two identical tables between databases using the links to the db and I'm having issues getting my correct join show lines that exist in a table and not the other. The purpose of the request is to view the items that exist in one but not the other and where the value is different between the elements. The Grp, layer and Name columns are PKs.

    So take the following data:
    DB1
    Grp     Name        Layer       Value
    Alpha   Key_One     ModA        1
    Beta    Key_Two     ModA        1
    Gamma   Key_Three   ModB        0
    Delta   Key_Four    ModA        True
    Epsilon Key_Five    ModB        Hat
    Zeta    Key_Six     ModB        Red
    
    DB2
    Grp     Name        Layer       Value
    Alpha   Key_One     ModA        0
    Beta    Key_Two     ModA        1
    Gamma   Key_Three   ModB        0
    Delta   Key_Four    ModA        False
    Epsilon Key_Five    ModA        Hat
    Eta     Key_Seven   ModB        0
    The result of the query should be:
    Grp     Name        Layer       DB1.Value    DB2.Value
    Alpha   Key_One     ModA        1            0
    Delta   Key_Four    ModA        True         False
    Epsilon Key_Five    ModA                     Hat
    Epsilon Key_Five    ModB        Hat
    Zeta    Key_Six     ModB        Red
    Eta     Key_Seven   ModB                     0
    I've been able to get the query to pull the differences when the record exists in both tables, but were not able to get when recording exists only in a single table. If it's important, I'm on 10.2.0.4.
    CREATE TABLE tab1 (grp VARCHAR2 (10), nm VARCHAR2 (15), layer VARCHAR2 (4), rec_value VARCHAR2 (10));
    CREATE TABLE tab2 (grp VARCHAR2 (10), nm VARCHAR2 (15), layer VARCHAR2 (4), rec_value VARCHAR2 (10));
    
    INSERT INTO tab1 VALUES ('Alpha', 'Key_One', 'ModA', '1');
    INSERT INTO tab1 VALUES ('Beta', 'Key_Two', 'ModA', '1');
    INSERT INTO tab1 VALUES ('Gamma', 'Key_Three', 'ModB', '0');
    INSERT INTO tab1 VALUES ('Delta', 'Key_Four', 'ModA', 'True');
    INSERT INTO tab1 VALUES ('Epsilon', 'Key_Five', 'ModB', 'Hat');
    INSERT INTO tab1 VALUES ('Zeta', 'Key_Six', 'ModB', 'Red');
    
    INSERT INTO tab2 VALUES ('Alpha', 'Key_One', 'ModA', '0');
    INSERT INTO tab2 VALUES ('Beta', 'Key_Two', 'ModA', '1');
    INSERT INTO tab2 VALUES ('Gamma', 'Key_Three', 'ModB', '0');
    INSERT INTO tab2 VALUES ('Delta', 'Key_Four', 'ModA', 'False');
    INSERT INTO tab2 VALUES ('Epsilon', 'Key_Five', 'ModA', 'Hat');
    INSERT INTO tab2 VALUES ('Eta', 'Key_Seven', 'ModB', '0');
    COMMIT;
    After the implementation of the above, I can run the following script which returns all but I want to exclude records where they correspond, in the example above, are GRPs beta and Gamma.
      SELECT NVL (tab1.grp, tab2.grp) grp, NVL (tab1.nm, tab2.nm) nm, NVL (tab1.layer, tab2.layer) layer, tab1.rec_value tab1_value,
             tab2.rec_value tab2_value
        FROM tab1 FULL OUTER JOIN tab2 ON tab1.grp = tab2.grp AND tab1.nm = tab2.nm AND tab1.layer = tab2.layer
    ORDER BY 1,2,3;
    
    GRP        NM              LAYER TAB1_VALUE TAB2_VALUE
    ---------- --------------- ----- ---------- ----------
    Alpha      Key_One         ModA  1          0         
    Beta       Key_Two         ModA  1          1         
    Delta      Key_Four        ModA  True       False     
    Epsilon    Key_Five        ModA             Hat       
    Epsilon    Key_Five        ModB  Hat                  
    Eta        Key_Seven       ModB             0         
    Gamma      Key_Three       ModB  0          0         
    Zeta       Key_Six         ModB  Red                  
    
    8 rows selected.
    Any help would be appreciated.

    Hello

    Just add a WHERE clause that makes tab1.rec_value and tab_2.rec_value are different, accounting for NULL values. (The only change I made to your application, in addition to the formatting, was to add a WHERE clause).
    If rec_value may not actually be NULL:

    SELECT  NVL (tab1.grp,          tab2.grp)     grp
    ,     NVL (tab1.nm,           tab2.nm)     nm
    ,     NVL (tab1.layer,      tab2.layer)      layer
    ,     tab1.rec_value                     tab1_value
    ,       tab2.rec_value                    tab2_value
    FROM           tab1
    FULL OUTER JOIN tab2     ON     tab1.grp   = tab2.grp
                           AND     tab1.nm        = tab2.nm
                   AND     tab1.layer = tab2.layer
    WHERE   DECODE ( tab1.rec_value
                , tab2.rec_value, 1
                          , 0
                ) = 0
    ORDER BY 1,2,3;
    

    If rec_value can be null, we must distinguish between the ranks, which is NULL because he wasn't match (and therefore should be included) and the lines where the two are really NULL (and therefore, should not be displayed).
    If one of the columns used to join the tables is NULL, the row is missing in one of the tables, and so forge displayed regardless of whether the rec_values is, so we can add a condtion to the WHERE clause:

    SELECT  NVL (tab1.grp,          tab2.grp)     grp
    ,     NVL (tab1.nm,           tab2.nm)     nm
    ,     NVL (tab1.layer,      tab2.layer)      layer
    ,     tab1.rec_value                     tab1_value
    ,       tab2.rec_value                    tab2_value
    FROM           tab1
    FULL OUTER JOIN tab2     ON     tab1.grp   = tab2.grp
                           AND     tab1.nm        = tab2.nm
                   AND     tab1.layer = tab2.layer
    WHERE   DECODE ( tab1.rec_value
                , tab2.rec_value, 1
                          , 0
                ) = 0
    OR     LEAST (tab1.grp, tab2.grp)     IS NULL
    ORDER BY 1,2,3;
    

    To test this, I added these 3 rows to the data:

    INSERT INTO tab1 VALUES ('Theta', 'Key_Seven', 'ModB', NULL);
    
    INSERT INTO tab2 VALUES ('Theta', 'Key_Seven', 'ModB', NULL);
    INSERT INTO tab2 VALUES ('Iota',  'Key_Seven', 'ModB', NULL);
    

    GRP = "Theta" should appear not, because the lines are identical in both tables.
    GRP = 'Iota' should be displayed, because it is present only in tab2.

  • Need help with the output of the query formatting

    Hello

    Here are the scripts to create the table and create test data:

    create table result (acct number(10), acct_nm varchar2(100), stage varchar2(10), target_pc number(10,2), long_target_pc number(10,2))
    /
    Insert into RESULT
       (ACCT, ACCT_NM, STAGE, TARGET_PC, LONG_TARGET_PC)
    Values
       (47042, 'Dora the explorer', 'AFTER', 33.6, 48)
    /  
    Insert into RESULT
       (ACCT, ACCT_NM, STAGE, TARGET_PC, LONG_TARGET_PC)
    Values
       (47042, 'Dora the explorer', 'BEFORE', 33.6, 48)
    /  
    Insert into RESULT
       (ACCT, ACCT_NM, STAGE, TARGET_PC, LONG_TARGET_PC)
    Values
       (41142, 'Bob the Builder', 'AFTER', 9.18, 20.4)
    /  
    Insert into RESULT
       (ACCT, ACCT_NM, STAGE, TARGET_PC, LONG_TARGET_PC)
    Values
       (41142, 'Bob the Builder', 'BEFORE', 9.18, 20.4)
    /  
    Insert into RESULT
       (ACCT, ACCT_NM, STAGE, TARGET_PC, LONG_TARGET_PC)
    Values
       (41086, 'Sofia the first', 'AFTER', 17.96, 51.3)
    /  
    Insert into RESULT
       (ACCT, ACCT_NM, STAGE, TARGET_PC, LONG_TARGET_PC)
    Values
       (41086, 'Sofia the first', 'BEFORE', 2.98, 8.5)
    /  
    Insert into RESULT
       (ACCT, ACCT_NM, STAGE, TARGET_PC, LONG_TARGET_PC)
    Values
       (41086, 'Sofia the first', 'BEFORE', 14.98, 42.8)
    /  
    COMMIT
    /
    
    

    I need output in the following format when I query this table:

    Account         Account Name        Stage       Target PC       Long Target PC
    41086           Sofia the first   
                                       BEFORE            2.98                  8.5
                                                        14.98                 42.8
                                       AFTER            17.96                 51.3
    41142           Bob the Builder                                                     
                                       BEFORE            9.18                 20.4
                                       AFTER             9.18                 20.4
    47042           Dora the explorer                                                     
                                       BEFORE           33.6                  48.0
                                       AFTER            33.6                  48.0
       
    Total Accounts = 3
    
    
    

    Here is what I tried but it does not gives me out I want (below referred to as the code):

    spool c:\break_test.txt
    column acct format 9999999999
    column acct_nm format a50
    column stage format a15
    column target_pc format 999.99
    column long_target_pc format 999.99
    break on acct, acct_nm, stage
    select * from result order by acct, stage desc
    
    
    

          41086 Sofia the first                                    BEFORE              2.98           8.50
          41086 Sofia the first                                    BEFORE             14.98          42.80
          41086 Sofia the first                                    AFTER              17.96          51.30
          41142 Bob the Builder                                    BEFORE              9.18          20.40
          41142 Bob the Builder                                    AFTER               9.18          20.40
          47042 Dora the explorer                                  BEFORE             33.60          48.00
          47042 Dora the explorer                                  AFTER              33.60          48.00
    
    

    Please tell us how to get there.

    Thanks in advance!

    Go back and check the syntax of the PAUSE command.

    SQL> column long_target_pc format 999.99
    SQL> break on acct, acct_nm, stage
    SP2-0158: unknown BREAK option "acct_nm,"
    

    The syntax must be

    sql> break on acct on acct_nm on stage
    

    SQL formatting * more reports

  • Need help with instr/Regexp for the query

    Hi people of Oracle

    I use Oracle

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
    With partitioning, OLAP, Data Mining and Real Application Testing options

    I have a few responses from students and the valid values are + / / (alphabet) o/p and spaces at the end of the scam only not in the middle.

    According to my condition, the registration number 2 3.4 must be in the request but I'm alone (chart 3).

    Can we use REG_EXP

    Help, please.

    Thanks in advance.

    Rajesh

    with x as)
    (
    SELECT '+-+-POPPPPPP' STUDENT_RESPONSE, 1 numero_enregistrement FROM DUAL Union all the
    SELECT ' + --AOPPPPPP++' STUDENT_RESPONSE, 2 numero_enregistrement FROM DUAL Union all the
    SELECT "+-+-OPPPPPP -' STUDENT_RESPONSE, 3 numero_enregistrement FROM DUAL union all
    SELECT '+-+-9OPPPPPP' STUDENT_RESPONSE, 4 numero_enregistrement FROM DUAL)
    )
    (SELECT NUMERO_ENREGISTREMENT,
    TRIM (STUDENT_RESPONSE) X
    WHERE
    ((INSTR (UPPER (TRIM (STUDENT_RESPONSE)),'-') = 0))
    OR (INSTR (UPPER (TRIM (STUDENT_RESPONSE)), '+') = 0)
    OR (INSTR (UPPER (TRIM (STUDENT_RESPONSE)), 'O') = 0)
    OR (INSTR (UPPER (TRIM (STUDENT_RESPONSE)), 'P') = 0)
    OR (INSTR (UPPER (TRIM (STUDENT_RESPONSE)),' ')! = 0)
    )
    )

    Hi, Renon,

    Rb2000rb65 wrote:
    Hi people of Oracle

    I use Oracle

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
    With partitioning, OLAP, Data Mining and Real Application Testing options

    Thanks for posting this (and the WITH clause for sample data). It is very useful.

    I have a few responses from students and the valid values are + / / (alphabet) o/p and spaces at the end of the scam only not in the middle.

    You combine several qeustions responses in a single VARCHAR2 column? It would be better to have a separate line for each question.

    According to my condition, the registration number 2 3.4 must be in the request but I'm alone (chart 3).

    What exactly are your needs? You try to find the rows where the student_response contains one of the forbidden characters, or if it contains a space anywhere, but at the end of the string?

    Can we use REG_EXP

    Yes, but it's pretty easy and probably more effective, do not use regular expressions in this case:
    Here's one way:

    SELECT     record_number
    ,     student_response
    FROM     x
    WHERE     TRANSLATE ( UPPER ( RTRIM (student_response, ' '))
                , 'X+-OP'
                , 'X'
                )     IS NOT NULL
    ;
    

    In other words, once you remove the spaces and all occurrences of '+', '-', 'o' or 'P', then the forbidden characters are left, and you want to select the line, if there is one of these.

    If you really, really want to use a regular expression:

    SELECT     record_number
    ,     student_response
    FROM     x
    WHERE     REGEXP_LIKE ( RTRIM (student_response)
                  , '[^-+OP]'          -- or '[^+OP-]', but not '[^+-OP]'.  Discuss amongst yourselves
                  , 'i'
                  )
    ;
    

    but, again, it will be probably slower than the first solution, using TRANSLATE.

    Published by: Frank Kulash, October 17, 2011 13:05

    Published by: Frank Kulash, October 17, 2011 13:41
    What follows is a bit simpler that TRANSLATE:

    SELECT     record_number
    ,     student_response
    FROM     x
    WHERE     RTRIM ( UPPER ( RTRIM (student_response, ' '))
               , '+-OP'
               )          IS NOT NULL
    ;
    
  • Need help with the COUNT in a query

    Hi all
    I have the following table. In this table, I try to get the number of records per month when its value (SIGNAGE_ONE_LANE_ROAD_AHEAD) is 'Yes' and gives me the number of fake. Anyone can you please point out where I'm wrong?
    AUDIT_DATE SIGNAGE_ONE_LANE_ROAD_AHEAD SIGNAGE_LANE_CLOSED_AHEAD

    05/01/2011 09:30 N/A N/A
    09/02/2011-11:50 Yes Yes
    21/02/2011-10:00 Yes Yes
    22/02/2011-07:00 N/A N/A
    07/03/2011-13:35 Yes n/a
    08/03/2011 09:15 N/A N/A
    09/03/2011 08:40 N/A N/A
    10/03/2011-10:00 N/A N/A
    11/03/2011 09:45 Yes Yes
    16/03/2011 08:45 Yes n/a
    17/03/2011 09:30 N/A N/A
    17/03/2011 12:05 N/A N/A
    17/03/2011-13:10 Yes n/a
    21/03/2011 10:30 N/A N/A
    22/03/2011 09:30 Yes n/a
    04/04/2011 11:20 Yes Yes
    05/04/2011 10:30 Yes Yes
    05/04/2011-10:45 Yes Yes
    08/04/2011 09:30 Yes Yes
    08/04/2011 12:45 N/A N/A
    13/04/2011 10:15 Yes Yes
    21/04/2011 08:45 N/A N/A
    SELECT   to_char(t.audit_date,'mm') as audit_month, t.signage_lane_closed_ahead,
             t.signage_one_lane_road_ahead,
             (CASE
                 WHEN t.signage_lane_closed_ahead = 'Yes'
                    THEN COUNT (t.signage_lane_closed_ahead)
                 ELSE 0
              END
             ) AS lane_closed_count
        FROM dw_safety_work_zone_audit t
        group by to_char(t.audit_date,'mm'), t.signage_lane_closed_ahead,t.SIGNAGE_ONE_LANE_ROAD_AHEAD
    ORDER BY to_char(t.audit_date,'mm')
    and the DataSet I get is
    AUDIT_MONTH SIGNAGE_LANE_CLOSED_AHEAD SIGNAGE_ONE_LANE_ROAD_AHEAD LANE_CLOSED_COUNT

    S/O S/O 1 0
    S/O S/O 2 0
    Yes Yes 2 2
    3 S/O S/O 0
    3 s/o Yes 0
    3 Yes n/a 3
    3 Yes Yes 1
    4 N/A N/A 0
    4 Yes Yes 5


    Thank you

    Hello

    thinkingeye wrote:

    SELECT   to_char(t.audit_date,'mm') as audit_month, t.signage_lane_closed_ahead,
    t.signage_one_lane_road_ahead,
    (CASE
    WHEN t.signage_lane_closed_ahead = 'Yes'
    THEN COUNT (t.signage_lane_closed_ahead)
    ELSE 0
    END
    ) AS lane_closed_count
    FROM dw_safety_work_zone_audit t
    group by to_char(t.audit_date,'mm'), t.signage_lane_closed_ahead,t.SIGNAGE_ONE_LANE_ROAD_AHEAD
    ORDER BY to_char(t.audit_date,'mm')
    

    You want to COUNT (CASE...), not CASE...

    The above code uses a CASE expression to display 0 or a NUMBER. When he shows the COUNTY, it is the full NUMBER in this column, not something conditional.

    You probably want somehting like:

    ...      COUNT ( CASE
                             WHEN t.signage_lane_closed_ahead = 'Yes'
                         THEN t.signage_lane_closed_ahead
                      END
                )     AS lane_closed_count
    

    In addition, you want to GROUP BY t.singage_lane_closed_ahead? Doing so means that you will get separate lines of output (with separate heads) for the 'Yes' and 'n/a '.

    Also, maybe you should use
    TRUNC (t.audit_date, 'mm') instead of
    To_char (t.audit_date, 'mm')

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

  • Need help with the API Explorer

    Hi all

    I am creating a workflow to automate certain tasks of P2V and I want to disconnect the NETWORK adapter prior to anyting on virtual machines. When everything is done, I want reconnect you this NIC I play with vCO for a few months now and I need to get help with the part of the script. I always managed to find a code but this time I did not find anything!

    So I need to script this part! I think I found a way to change the connection settings of the VMXNET3 NETWORK adapter with this part of the code:

    System.getModule("com.vmware.library.vc.vm.spec.config.device").getVirtualVmxnet3(backing,connectable,controllerKey,deviceInfo,key,unitNumber,addressType,macAddress,wakeOnLanEnabled)
    var connectset = new VcVirtualDeviceConnectInfo();
    connectset.connected = false;
    connectset.startConnected = false;
    

    Now, I need to find the way to set these parameters to a VM VMXNET3 adapter?

    How to off the virtual machine to these settings?

    Thanks for your help!

    If you are connected to a distributed switch, they canned for this com.vmware.library.vc.networking.connectVmNicNumberToVirtualDistributedPortgroup action.  If this isn't a vds connect you to, then you need to change then it will have to be slightly modified to use normal NIC instead of vds support.  You will also need to add these lines to the device configuration section:

    devicespec. Device.connectable = new VcVirtualDeviceConnectInfo();

    devicespec. Device.connectable.Connected = true;

    devicespec.device.connectable.startConnected = true;

    I copied this action and added these 3 lines to achieve what it looks like you are trying to do.  We don't really use standard switches in our environment.

    Paul

  • When you type a query in the bar always double the third letter, for example, research, if I want to write a 'youtube' written "youutube" what to do, help

    When you type a query in the bar always double the third letter, for example, research, if I want to write a 'youtube' written "youutube" what to do, help

    Hello chilli.willi, try Firefox Safe Mode to see if the problem goes away. Firefox Safe mode is a troubleshooting mode that temporarily disables hardware acceleration, restores some settings and disables add-ons (extensions and themes).

    If Firefox is open, you can restart Firefox Safe mode in the Help menu:

    • Click the menu button

      click Help

      then select restart with disabled modules.

    When the Firefox Safe Mode window appears, select "start mode safe."

    If the problem is not present in Firefox Safe Mode, your problem is probably caused by an extension, theme or hardware acceleration. Please follow the steps described in the section Troubleshooting extensions, themes and problems of hardware acceleration to resolve common Firefox problems to find the cause.

    To exit safe mode of Firefox, simply close Firefox and wait a few seconds before you open Firefox for normal use again.

    When find you what is causing your problems, please let us know. This might help others with the same problem.

  • Seeking help with a problem with the LR I use LR CC on a laptop, when you try to export a picture to an external hard drive, I am now without apparent reason to get the following message, "could not create a JPEG sponsor limit you 92 k Bytes.Plea.

    Seeking help with a problem with the LR


    I use LR CC on a laptop, when you try to export a picture to an external hard drive, I am now without apparent reason to get the following message.

    "Could not create a respondent JPEG limit you 92 k Bytes.Please increase the size limit files
    . (1).

    .....

    I tried to increase the size of the file several times,

    I left LR

    I restarted the computer.


    Any help or advice for this problem will be greatly appreciated


    Thanks in advance


    @stu

    Not because of the number of pixels, in this photo and the chosen level of quality there is no possible way to create a JPG file to the size of file you requested. You must change your export settings.

    Show us a copy of the export dialog box, so we can see clearly the part file setting and the size of the Image.

    Also indicate the number of this image (width and height) pixels after cropping (as appropriate) and prior to export.

  • Need help with query between 2 dates

    Hello

    I did not SEE in a long time and need help with a simple query.

    I have a table of DB access with 3 fields, name, date and number

    What I want is to create a query to retrieve all the names between 2 dates

    When I ask the date field, the results are showing in this formats 2013-07-12 00:00:00

    Here's my query

    < cfquery datasource = 'mydb' name = 'test' >

    SELECT name from myTable

    where edate between ' 2011-01-01 00:00:00 ' AND ' 2013-01-01 00:00:00 '

    < / cfquery >

    < cfoutput query = 'test' >

    #name #.

    < / cfoutput >

    What I get is this error

    ODBC = 22005 (assignment error) error code

    [Microsoft] [ODBC Microsoft Access driver] Type mismatch of data in the expression of the criteria.

    Don't know what I'm doing wrong here.

    Please let me know.

    Thank you

    SELECT ename

    FROM MyTable

    WHERE edate BETWEEN

    AND

    #ename #.

  • Need help with a query to group by return qroups with no result

    I have the following query that checks the number of items maintenance has been done for each paragraph in a support order.
    It lists all the paragraphs being checked it and the number of maintenance activities were conducted for that paragraph.
    It works very well in most of the cases, except some of the facilities to break their equipment into subcatagories from a specific facility specified in the lpm.equipment_ident field.
    For example, the tables and the data below are for the installation of ATL, which is breaking down for channels A and B maintenance activities

    The following query illustrates 10 maintenance activities for installation ATL and the query must be 5 for ATL channel A and 5 activities for ATL channel B

    This is the query, output current, output desired and all the SQL required to create the tables and data. I am using Oracle 11g

    Any help would be appreciated.
    -- Query
    SELECT req.publication_paragraph_number AS publication_paragraph
    -- , req.description
    , req.frequency
    , case upper (req.frequency) 
    WHEN 'DAILY'           THEN 365 
    WHEN 'WEEKLY'          THEN 52 
    WHEN 'MONTHLY'         THEN 12 
    WHEN 'QUARTERLY'       THEN 4 
    WHEN 'SEMIANNUALLY'    THEN 2
    WHEN 'ANNUALLY'        THEN 1
    ELSE 0
    END as num_req, 
    MAX(lpm.equipment_ident) AS equipment_ident
    , COUNT(fsep.fac_id) as activities_performed 
    FROM pm_requirements_table req 
    LEFT OUTER JOIN lpm_paragraph_mapping_table pmap 
    ON req.publication_order = pmap.publication_order AND req.publication_paragraph_number = pmap.publication_paragraph 
    LEFT OUTER JOIN lpm
    ON trim(lpm.publication_paragraph) = pmap.paragraph_alias_mapping 
    AND TRIM(lpm.publication_order) = '6310.19A' 
    AND TRUNC(lpm.start_date, 'YEAR') = TO_DATE('01/01/2010', 'MM/DD/YYYY')
    AND lpm.fac_ident = 'ATL' 
    LEFT OUTER JOIN fsep 
    ON fsep.fac_id = lpm.fac_ident 
    AND fsep.facility = lpm.fac_type
    GROUP BY req.publication_paragraph_number, req.description, req.frequency
    ORDER BY req.publication_paragraph_number;
    -- Current Output
    "PUBLICATION_PARAGRAPH"       "FREQUENCY"                   "NUM_REQ"              "EQUIPMENT_IDENT"             "ACTIVITIES_PERFORMED"
    "161A"                         "WEEKLY"                      "52"                          "CHAN B"                             "10"
    "161B"                         "WEEKLY"                      "52"                          "CHAN B"                             "10"
    "161C"                         "WEEKLY"                      "52"                          "CHAN B"                             "10"
    "161D(1)"                      "WEEKLY"                      "52"                          ""                                    "0"
    "161D(2)"                      "WEEKLY"                      "52"                          ""                                    "0"
    "161D(3)"                      "WEEKLY"                      "52"                          ""                                    "0"
    "161D(4)"                      "WEEKLY"                      "52"                          ""                                    "0"
    "161D(5)"                      "WEEKLY"                      "52"                          ""                                    "0"
    "161D(6)"                      "WEEKLY"                      "52"                          ""                                    "0"
    "161E"                         "WEEKLY"                      "52"                          ""                                    "0"
    "161F"                         "WEEKLY"                      "52"                          ""                                    "0"
    "161G"                         "WEEKLY"                      "52"                          ""                                    "0"
    "161H"                         "WEEKLY"                      "52"                          ""                                    "0"
    "161I"                         "WEEKLY"                      "52"                          ""                                    "0"
    "161J"                         "WEEKLY"                      "52"                          ""                                    "0"
    "161K"                         "WEEKLY"                      "52"                          ""                                    "0"
    -- Desired Output
    "PUBLICATION_PARAGRAPH"       "FREQUENCY"                   "NUM_REQ"              "EQUIPMENT_IDENT"             "ACTIVITIES_PERFORMED"
    "161A"                         "WEEKLY"                      "52"                          "CHAN A"                              "5"
    "161A"                         "WEEKLY"                      "52"                          "CHAN B"                              "5"
    "161B"                         "WEEKLY"                      "52"                          "CHAN A"                              "5"
    "161B"                         "WEEKLY"                      "52"                          "CHAN B"                              "5"
    "161C"                         "WEEKLY"                      "52"                          "CHAN A"                              "5"
    "161C"                         "WEEKLY"                      "52"                          "CHAN B"                              "5"
    "161D(1)"                      "WEEKLY"                      "52"                          ""                                    "0"
    "161D(2)"                      "WEEKLY"                      "52"                          ""                                    "0"
    "161D(3)"                      "WEEKLY"                      "52"                          ""                                    "0"
    "161D(4)"                      "WEEKLY"                      "52"                          ""                                    "0"
    "161D(5)"                      "WEEKLY"                      "52"                          ""                                    "0"
    "161D(6)"                      "WEEKLY"                      "52"                          ""                                    "0"
    "161E"                         "WEEKLY"                      "52"                          ""                                    "0"
    "161F"                         "WEEKLY"                      "52"                          ""                                    "0"
    "161G"                         "WEEKLY"                      "52"                          ""                                    "0"
    "161H"                         "WEEKLY"                      "52"                          ""                                    "0"
    "161I"                         "WEEKLY"                      "52"                          ""                                    "0"
    "161J"                         "WEEKLY"                      "52"                          ""                                    "0"
    "161K"                         "WEEKLY"                      "52"                          ""                                    "0"
    -- Tables and Data
    CREATE TABLE "LPM"
      (
        "LOG_ID"              NUMBER(22,0) NOT NULL ENABLE,
        "FAC_IDENT"           VARCHAR2(5 BYTE),
        "FAC_TYPE"            VARCHAR2(5 BYTE),
        "CODE_CATEGORY"       NUMBER(22,0) NOT NULL ENABLE,
        "SUPPLEMENTAL_CODE"   VARCHAR2(1 BYTE),
        "MAINT_ACTION_CODE"   VARCHAR2(1 BYTE),
        "INTERRUPT_CONDITION" VARCHAR2(22 BYTE),
        "ATOW_CODE"           VARCHAR2(22 BYTE),
        "SECTOR_CODE"         VARCHAR2(5 BYTE),
        "LOG_STATUS"          VARCHAR2(3 BYTE) NOT NULL ENABLE,
        "START_DATE" DATE,
        "START_DATETIME" VARCHAR2(22 BYTE),
        "END_DATE" DATE,
        "END_DATETIME"      VARCHAR2(22 BYTE),
        "MODIFIED_DATETIME" VARCHAR2(22 BYTE),
        "WR_AREA"           VARCHAR2(6 BYTE),
        "SHORT_NAME"        VARCHAR2(15 BYTE),
        "EQUIPMENT_IDENT"   VARCHAR2(15 BYTE),
        "INTERVAL_CODE"     VARCHAR2(255 BYTE),
        "EARLIEST_DATE"     VARCHAR2(4000 BYTE),
        "EARLIEST_DATETIME" VARCHAR2(255 BYTE),
        "SCHEDULED_DATE" DATE,
        "SCHEDULED_DATETIME" VARCHAR2(22 BYTE),
        "LATEST_DATE" DATE,
        "LATEST_DATETIME"                VARCHAR2(22 BYTE),
        "WR_CREW_UNIT"                   VARCHAR2(10 BYTE),
        "WR_WATCH"                       VARCHAR2(1 BYTE),
        "PUBLICATION_ORDER"              VARCHAR2(30 BYTE),
        "PUBLICATION_ORDER_ORIGINAL"     VARCHAR2(30 BYTE),
        "PUBLICATION_PARAGRAPH"          VARCHAR2(30 BYTE),
        "PUBLICATION_PARAGRAPH_ORIGINAL" VARCHAR2(30 BYTE),
        "NUMBER_OF_TASKS"                VARCHAR2(25 BYTE),
        "LOG_SUMMARY"                    VARCHAR2(255 BYTE),
        "COMMENTS" CLOB,
        "RELATED_LOGS" CLOB,
        "LPMANTAC_ID" NUMBER
      );
    
    CREATE TABLE "FSEP"
      (
        "FAC_ID"               VARCHAR2(10 BYTE),
        "FACILITY"             VARCHAR2(5 BYTE),
        "FAC_LOCATION"         VARCHAR2(13 BYTE),
        "FAC_STATE"            VARCHAR2(2 BYTE),
        "REGION"               VARCHAR2(2 BYTE),
        "COST_CENTER"          VARCHAR2(8 BYTE) NOT NULL ENABLE,
        "ATOW_ORG"             VARCHAR2(150 BYTE),
        "ATOW_ORG_DESCRIPTION" VARCHAR2(150 BYTE),
        "SVC_AREA"             VARCHAR2(5 BYTE),
        "SECTOR_CODE"          VARCHAR2(5 BYTE),
        "FAC_CODE"             VARCHAR2(20 BYTE),
        "FAC_STATUS"           CHAR(1 BYTE) NOT NULL ENABLE,
        "RESTORATION_CODE"     VARCHAR2(2 BYTE),
        "RESPONSIBILITY_CODE"  CHAR(1 BYTE),
        "POWER_CODE"           CHAR(1 BYTE),
        "FAC_STATUS_DATE" DATE,
        "FAC_SWAP_DATE" DATE,
        "CHANGE_DATE"        VARCHAR2(22 BYTE),
        "GSA_ADDRESS"        VARCHAR2(15 BYTE),
        "INV"                VARCHAR2(2 BYTE),
        "SDP_TYPE"           VARCHAR2(5 BYTE),
        "SDP_IDENT"          VARCHAR2(4 BYTE),
        "CONTROL_IDENT"      VARCHAR2(10 BYTE),
        "REMOTE_IDENT"       VARCHAR2(10 BYTE),
        "MONITOR_IDENT"      VARCHAR2(4 BYTE),
        "RUNWAY"             VARCHAR2(3 BYTE),
        "ASSOC_AIRPORT"      VARCHAR2(4 BYTE),
        "FAC_MPS_SITE"       CHAR(4 BYTE),
        "FREQS_IN_PLACE"     NUMBER(22,0),
        "CONGRESSIONAL_DIS"  VARCHAR2(2 BYTE),
        "CONTRACT_MAINT_PER" NUMBER(22,0),
        "AIR_COND"           CHAR(1 BYTE),
        "FAC_UNITS"          NUMBER(22,0),
        "ET_PRIMARY_IDENT"   VARCHAR2(4 BYTE),
        "ET_PRIMARY_TYPE"    VARCHAR2(5 BYTE),
        "ENV_PRIMARY_IDENT"  VARCHAR2(4 BYTE),
        "ENV_PRIMARY_TYPE"   VARCHAR2(5 BYTE),
        "FAC_CODE_DESC"      VARCHAR2(100 BYTE),
        "STATUS_DESC"        VARCHAR2(50 BYTE),
        "RESTORATION_DESC"   VARCHAR2(32 BYTE),
        "POWER_DESC"         VARCHAR2(500 BYTE),
        "LATITUDE"           VARCHAR2(150 BYTE),
        "LONGITUDE"          VARCHAR2(150 BYTE),
        "ELEVATION"          VARCHAR2(22 BYTE),
        "MOD_COUNT"          VARCHAR2(22 BYTE),
        "HYPERLINK"          VARCHAR2(255 BYTE),
        "FSEPANTAC_ID"       NUMBER
    );
    
    CREATE TABLE "LPM_PARAGRAPH_MAPPING_TABLE"
      (
        "PUBLICATION_ORDER"       VARCHAR2(30 BYTE),
        "PUBLICATION_PARAGRAPH"   VARCHAR2(30 BYTE),
        "PARAGRAPH_ALIAS_MAPPING" VARCHAR2(30 BYTE),
        "LPMTANTAC_ID"            NUMBER
    );
    
    CREATE TABLE "PM_REQUIREMENTS_TABLE"
      (
        "PUBLICATION_ORDER"            VARCHAR2(30 BYTE),
        "PUBLICATION_PARAGRAPH_NUMBER" VARCHAR2(30 BYTE),
        "DESCRIPTION"                  VARCHAR2(4000 BYTE),
        "FREQUENCY"                    VARCHAR2(30 BYTE),
        "CHECK_OR_MAINTENANCE"         VARCHAR2(22 BYTE),
        "PRTANTAC_ID"                  NUMBER);
    
    Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (108306002,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('02-MAY-10','DD-MON-RR'),'05/02/2010 21:00',to_date('02-MAY-10','DD-MON-RR'),'05/02/2010 21:30','05/03/2010 1:07','RADAR','SYS','CHAN B','W','05/02/2010','05/02/2010 0:00',to_date('05-MAY-10','DD-MON-RR'),'05/05/2010 0:00',to_date('08-MAY-10','DD-MON-RR'),'05/08/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14297);
    Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (108306102,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('02-MAY-10','DD-MON-RR'),'05/02/2010 21:00',to_date('02-MAY-10','DD-MON-RR'),'05/02/2010 21:30','05/03/2010 1:07','RADAR','SYS','CHAN A','W','05/02/2010','05/02/2010 0:00',to_date('05-MAY-10','DD-MON-RR'),'05/05/2010 0:00',to_date('08-MAY-10','DD-MON-RR'),'05/08/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14298);
    Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (104188402,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('26-APR-10','DD-MON-RR'),'4/26/2010 13:33',to_date('26-APR-10','DD-MON-RR'),'4/26/2010 13:46','4/26/2010 15:23','RADAR','SYS','CHAN A','W','4/25/2010','4/25/2010 0:00',to_date('28-APR-10','DD-MON-RR'),'4/28/2010 0:00',to_date('01-MAY-10','DD-MON-RR'),'05/01/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14306);
    Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (104188502,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('26-APR-10','DD-MON-RR'),'4/26/2010 13:33',to_date('26-APR-10','DD-MON-RR'),'4/26/2010 13:46','4/26/2010 15:23','RADAR','SYS','CHAN B','W','4/25/2010','4/25/2010 0:00',to_date('28-APR-10','DD-MON-RR'),'4/28/2010 0:00',to_date('01-MAY-10','DD-MON-RR'),'05/01/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14307);
    Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (101223702,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 1:30',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 2:10','4/19/2010 3:12','RADAR','SYS','CHAN B','W','4/18/2010','4/18/2010 0:00',to_date('21-APR-10','DD-MON-RR'),'4/21/2010 0:00',to_date('24-APR-10','DD-MON-RR'),'4/24/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14322);
    Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (101223802,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 1:30',to_date('19-APR-10','DD-MON-RR'),'4/19/2010 2:10','4/19/2010 3:12','RADAR','SYS','CHAN A','W','4/18/2010','4/18/2010 0:00',to_date('21-APR-10','DD-MON-RR'),'4/21/2010 0:00',to_date('24-APR-10','DD-MON-RR'),'4/24/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14323);
    Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (96642402,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('11-APR-10','DD-MON-RR'),'04/11/2010 11:10',to_date('11-APR-10','DD-MON-RR'),'04/11/2010 11:15','04/11/2010 12:51','RADAR','SYS','CHAN B','W','04/11/2010','04/11/2010 0:00',to_date('14-APR-10','DD-MON-RR'),'4/14/2010 0:00',to_date('17-APR-10','DD-MON-RR'),'4/17/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14335);
    Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (96642302,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('11-APR-10','DD-MON-RR'),'04/11/2010 11:05',to_date('11-APR-10','DD-MON-RR'),'04/11/2010 11:10','04/11/2010 12:51','RADAR','SYS','CHAN A','W','04/11/2010','04/11/2010 0:00',to_date('14-APR-10','DD-MON-RR'),'4/14/2010 0:00',to_date('17-APR-10','DD-MON-RR'),'4/17/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14336);
    Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (92805502,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 18:10',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 18:22','04/07/2010 19:04','RADAR','SYS','CHAN A','W','04/04/2010','04/04/2010 0:00',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 0:00',to_date('10-APR-10','DD-MON-RR'),'04/10/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14342);
    Insert into lpm (LOG_ID,FAC_IDENT,FAC_TYPE,CODE_CATEGORY,SUPPLEMENTAL_CODE,MAINT_ACTION_CODE,INTERRUPT_CONDITION,ATOW_CODE,SECTOR_CODE,LOG_STATUS,START_DATE,START_DATETIME,END_DATE,END_DATETIME,MODIFIED_DATETIME,WR_AREA,SHORT_NAME,EQUIPMENT_IDENT,INTERVAL_CODE,EARLIEST_DATE,EARLIEST_DATETIME,SCHEDULED_DATE,SCHEDULED_DATETIME,LATEST_DATE,LATEST_DATETIME,WR_CREW_UNIT,WR_WATCH,PUBLICATION_ORDER,PUBLICATION_ORDER_ORIGINAL,PUBLICATION_PARAGRAPH,PUBLICATION_PARAGRAPH_ORIGINAL,NUMBER_OF_TASKS,LOG_SUMMARY,COMMENTS,RELATED_LOGS,LPMANTAC_ID) values (92805402,'ATL','ASR',50,'0','P',null,'WEQ1C','SO1LB','C',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 17:53',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 18:05','04/07/2010 19:04','RADAR','SYS','CHAN B','W','04/04/2010','04/04/2010 0:00',to_date('07-APR-10','DD-MON-RR'),'04/07/2010 0:00',to_date('10-APR-10','DD-MON-RR'),'04/10/2010 0:00','RADR',null,'6310.19A','6310.19A','161A-J','161 A-J','15',null, EMPTY_CLOB(), EMPTY_CLOB(),14343);
    
    Insert into fsep (FAC_ID,FACILITY,FAC_LOCATION,FAC_STATE,REGION,COST_CENTER,ATOW_ORG,ATOW_ORG_DESCRIPTION,SVC_AREA,SECTOR_CODE,FAC_CODE,FAC_STATUS,RESTORATION_CODE,RESPONSIBILITY_CODE,POWER_CODE,FAC_STATUS_DATE,FAC_SWAP_DATE,CHANGE_DATE,GSA_ADDRESS,INV,SDP_TYPE,SDP_IDENT,CONTROL_IDENT,REMOTE_IDENT,MONITOR_IDENT,RUNWAY,ASSOC_AIRPORT,FAC_MPS_SITE,FREQS_IN_PLACE,CONGRESSIONAL_DIS,CONTRACT_MAINT_PER,AIR_COND,FAC_UNITS,ET_PRIMARY_IDENT,ET_PRIMARY_TYPE,ENV_PRIMARY_IDENT,ENV_PRIMARY_TYPE,FAC_CODE_DESC,STATUS_DESC,RESTORATION_DESC,POWER_DESC,LATITUDE,LONGITUDE,ELEVATION,MOD_COUNT,HYPERLINK,FSEPANTAC_ID) values ('ATL','ASR','ATLANTA','GA','SO','081LB','WEQ1C','Hartsfield Radar SSC','ESA','SO1LB','453ACA','D','4','A','A',to_date('01-OCT-50','DD-MON-RR'),to_date('01-OCT-95','DD-MON-RR'),'11/17/2010 8:51','43JW','RD','TRACO','A80','A80','ATL','A80',null,'ATL','ZTL ',0,'5',0,'A',1,null,null,null,null,'ASR-9   STANDARD FACILITY','Commissioned/Full Service','Up to 4 Hours','Denotes a commercial power source a standby engine generator and an Uninterruptible Power Supply (UPS).  This configuration shall provide uninterruptible conditioned power with AC voltage in and AC voltage out.','33.62875','-8.43003','1030','2','http://technet.faa.gov/fsep/fsepDetail.asp?recordno=ASRATL',32084);
    Insert into fsep (FAC_ID,FACILITY,FAC_LOCATION,FAC_STATE,REGION,COST_CENTER,ATOW_ORG,ATOW_ORG_DESCRIPTION,SVC_AREA,SECTOR_CODE,FAC_CODE,FAC_STATUS,RESTORATION_CODE,RESPONSIBILITY_CODE,POWER_CODE,FAC_STATUS_DATE,FAC_SWAP_DATE,CHANGE_DATE,GSA_ADDRESS,INV,SDP_TYPE,SDP_IDENT,CONTROL_IDENT,REMOTE_IDENT,MONITOR_IDENT,RUNWAY,ASSOC_AIRPORT,FAC_MPS_SITE,FREQS_IN_PLACE,CONGRESSIONAL_DIS,CONTRACT_MAINT_PER,AIR_COND,FAC_UNITS,ET_PRIMARY_IDENT,ET_PRIMARY_TYPE,ENV_PRIMARY_IDENT,ENV_PRIMARY_TYPE,FAC_CODE_DESC,STATUS_DESC,RESTORATION_DESC,POWER_DESC,LATITUDE,LONGITUDE,ELEVATION,MOD_COUNT,HYPERLINK,FSEPANTAC_ID) values ('ATL','GS','ATLANTA','GA','SO','081MB','WEQ1A','Hartsfield Nav/Comm SSC','ESA','SO1MB','314JAH','D','24','A','D',to_date('18-NOV-49','DD-MON-RR'),to_date('01-DEC-96','DD-MON-RR'),'3/4/2009 14:40','43JX','21','ATCT','ATL','ATL',null,'A80','08R','ATL','ZTL ',0,'5',0,'A',1,null,null,null,null,'MARK 20 CAPTURE EFFECT CAT III W/RMM','Commissioned/Full Service','Up to 24 Hours','Denotes a commercial power source and a battery standby power system.  A UPS is not included in this category.','33.64788','-84.43426','1012','2','http://technet.faa.gov/fsep/fsepDetail.asp?recordno=GSATL',32109);
    
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161A','161',1708);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161A','161A-J',1709);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161B','161',1736);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161B','161A-J',1737);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161',1765);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161A-J',1766);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161(A-->K)',1769);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161(A-K)',1774);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161C','161.(A-C).',1775);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(1)','161',1793);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(1)','161161 A-J',1794);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(2)','161',1821);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(2)','161 A-J',1822);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161D(2)','161(A-->K)',1825);
    Insert into LPM_PARAGRAPH_MAPPING_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH,PARAGRAPH_ALIAS_MAPPING,LPMTANTAC_ID) values ('6310.19A','161K','161.K',1825);
    
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161A','Check transmitter average rf power output','WEEKLY',null,3);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161B','Check transmitter VSWR','WEEKLY',null,4);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161C','Check RMS transmitter pulse width','WEEKLY',null,5);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(1)','Check filament current','WEEKLY',null,6);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(2)','Check focus coil current','WEEKLY',null,7);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(3)','Check Klystron voltage','WEEKLY',null,8);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(4)','Check Klystron current','WEEKLY',null,9);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(5)','Check PFN voltage','WEEKLY',null,10);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161D(6)','Check vacuum pump current','WEEKLY',null,11);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161E','Check target receiver MDS','WEEKLY',null,12);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161F','Check target receiver NF','WEEKLY',null,13);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161G','Check target receiver recovery','WEEKLY',null,14);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161H','Check weather receiver MDS','WEEKLY',null,15);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161I','Check weather receiver NF','WEEKLY',null,16);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161J','Check weather receiver recovery','WEEKLY',null,17);
    Insert into PM_REQUIREMENTS_TABLE (PUBLICATION_ORDER,PUBLICATION_PARAGRAPH_NUMBER,DESCRIPTION,FREQUENCY,CHECK_OR_MAINTENANCE,PRTANTAC_ID) values ('6310.19A','161K','Check spare modem operation','WEEKLY',null,18);
    Published by: George Heller on July 20, 2011 13:45

    Published by: George Heller on July 20, 2011 13:46

    Published by: George Heller on July 20, 2011 13:48

    Hi, George.

    I think I understand now!
    You want outer join table req on the result of all the other joined tables. You want all the lines of the req to be represented in the result set, even if they have no match in the other tables, but it is the only outer join you want. You don't want to necessarily, for example, all rows in the table pmap represented. In this case, the join involving req should be an outer join, but all the other joins are inner joins.

    Here's a way to do it:

    SELECT    req.publication_paragraph_number AS publication_paragraph
    -- ,        req.description
    ,         req.frequency
    ,        CASE   UPPER (req.frequency)
               WHEN 'DAILY'           THEN 365
               WHEN 'WEEKLY'          THEN  52
               WHEN 'MONTHLY'         THEN  12
               WHEN 'QUARTERLY'       THEN   4
               WHEN 'SEMIANNUALLY'    THEN   2
               WHEN 'ANNUALLY'        THEN   1
               ELSE 0
           END                    AS num_req
    ,       lpm.equipment_ident
    ,        COUNT (fsep.fac_id)          AS activities_performed
    FROM             pm_requirements_table          req
    LEFT OUTER JOIN (
                            lpm_paragraph_mapping_table     pmap
              JOIN  lpm
                                       ON   TRIM (lpm.publication_paragraph) = pmap.paragraph_alias_mapping
                                       AND  TRIM (lpm.publication_order)         = '6310.19A'
                                       AND  TRUNC (lpm.start_date, 'YEAR')   = TO_DATE ('01/01/2010', 'MM/DD/YYYY')
                                       AND  lpm.fac_ident                   = 'ATL'
                    JOIN  fsep
                                       ON   fsep.fac_id     = lpm.fac_ident
                                       AND  fsep.facility = lpm.fac_type
              )
                                     ON       req.publication_order             = pmap.publication_order
                             AND         req.publication_paragraph_number = pmap.publication_paragraph
    GROUP BY  req.publication_paragraph_number, req.description, req.frequency, lpm.equipment_ident
    ORDER BY  req.publication_paragraph_number
    ;
    

    Only the FROM clause has changed since yesterday.
    Output:

    `                                      ACTIV
    PUBLICAT                               ITIES
    ION_PARA                      EQUIPMEN _PERF
    GRAPH    FREQUENCY    NUM_REQ T_IDENT  ORMED
    -------- --------- ---------- -------- -----
    161A     WEEKLY            52 CHAN A       5
    161A     WEEKLY            52 CHAN B       5
    161B     WEEKLY            52 CHAN A       5
    161B     WEEKLY            52 CHAN B       5
    161C     WEEKLY            52 CHAN A       5
    161C     WEEKLY            52 CHAN B       5
    161D(1)  WEEKLY            52              0
    161D(2)  WEEKLY            52              0
    161D(3)  WEEKLY            52              0
    161D(4)  WEEKLY            52              0
    161D(5)  WEEKLY            52              0
    161D(6)  WEEKLY            52              0
    161E     WEEKLY            52              0
    161F     WEEKLY            52              0
    161G     WEEKLY            52              0
    161H     WEEKLY            52              0
    161I     WEEKLY            52              0
    161J     WEEKLY            52              0
    161K     WEEKLY            52              0
    
  • Help with time operations invloving the SQL query

    I created 2 tables in my SQL. One is the user_info_table table that stores the connection time and time zone of login for each user. The other is the post_table that stores user postid, who makes the post time post and time zone for each message.
    CREATE TABLE user_info
    (
    user_id VARCHAR(20), 
    login_date DATE,
    login_time_zone VARCHAR(20),
    PRIMARY KEY (user_id)
    );
    CREATE TABLE post_table
    (
    post_id VARCHAR(20),  
    user_id VARCHAR(20), 
    datepost DATE,  
    time_zone VARCHAR(20),
    PRIMARY KEY (post_id),
    FOREIGN KEY (user_id) REFERENCES user_info(user_id) ON DELETE CASCADE
    ) ;
    Some examples of data for my paintings is as below.
    INSERT INTO user_info VALUES( 'u1', to_date('9/17/2009 20:00','MM/DD/YYYY mi:ss'), -2 );
    INSERT INTO user_info VALUES( 'u2', to_date('9/17/2009 19:55','MM/DD/YYYY mi:ss'), -4 );
    
    INSERT INTO post_table VALUES( 'p1', 'u1', to_date('9/17/2009 20:50','MM/DD/YYYY mi:ss'), 6 );
    INSERT INTO post_table VALUES( 'p2', 'u2', to_date('9/17/2009 20:30','MM/DD/YYYY mi:ss'), -5 );
    INSERT INTO post_table VALUES( 'p3', 'u2', to_date('9/18/2009 6:00','MM/DD/YYYY mi:ss'), 2 );
    INSERT INTO post_table VALUES( 'p4', 'u1', to_date('9/17/2009 21:00','MM/DD/YYYY mi:ss'), -3 );
    I need to write a SQL query which - is the user whose time difference between the time of the connection and the last time when he or she wrote a post is the smallest. I need to consider the time zones here as well.

    I am not sure if time_zone must be of type VARCHAR or TIMESTAMP then have created as a VARCHAR in my paintings.

    Someone help me please to form this query.

    PS: How can I tags < code > user in this forum to write sql statements.

    Published by: user11994430 on October 9, 2009 17:59

    You can do this by adding a clause of "HAVING" as shown below. However, with your test defined data it returns ZERO rows because for all users of the MAX (DATEPOST) IS LESS than MAX (LOGIN_DATE)

    SELECT     USER_ID
    FROM
    (
         SELECT     USER_ID
         ,     DENSE_RANK() OVER (ORDER BY POST_LOGIN_DIFF) RNK
         FROM
         (
              SELECT     USER_INFO.USER_ID
              ,     MAX(DATEPOST) - MAX(LOGIN_DATE) AS POST_LOGIN_DIFF
              FROM     USER_INFO
              JOIN     POST_TABLE     ON POST_TABLE.USER_ID = USER_INFO.USER_ID
              GROUP BY USER_INFO.USER_ID
              HAVING      MAX(DATEPOST) > MAX(LOGIN_DATE)
         )
    )
    WHERE RNK = 1
    
  • Help with making SQL query references to column aliases in the Case statement

    I need help with a sql query that I'm trying. I can go about it the wrong way, but I would be grateful if I could get any suggestions on possible solutions. This is my query:


    SELECT DISTINCT spriden_pidm, spriden_id id, spriden_last_name | ',' | spriden_first_name name,

    CASE
    WHEN rcresar_comm_code_01 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_01
    WHEN rcresar_comm_code_02 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_02
    WHEN rcresar_comm_code_03 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_03
    WHEN rcresar_comm_code_04 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_04
    WHEN rcresar_comm_code_05 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_05
    WHEN rcresar_comm_code_06 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_06
    WHEN rcresar_comm_code_07 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_07
    WHEN rcresar_comm_code_08 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_08
    WHEN rcresar_comm_code_09 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_09
    WHEN rcresar_comm_code_10 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_10
    END acg_elig_comm_code

    CASE
    WHEN acg_elig_comm_code = ' 268' THEN 'rigorous HS course. "
    WHEN acg_elig_comm_code = '269' THEN ' 2 or several AP or IB"
    WHEN acg_elig_comm_code = '270' THEN 'NOC as possible ".
    END comm_code_description

    OF spriden, rcresar, rcrapp1

    WHERE (rcresar_comm_code_01 IN ('268 ', '269', ' 270')

    OR rcresar_comm_code_02 ('268 ', '269', ' 270')

    OR rcresar_comm_code_03 ('268 ', '269', ' 270')

    OR rcresar_comm_code_04 ('268 ', '269', ' 270')

    OR rcresar_comm_code_05 ('268 ', '269', ' 270')

    OR rcresar_comm_code_06 ('268 ', '269', ' 270')

    OR rcresar_comm_code_07 ('268 ', '269', ' 270')

    OR rcresar_comm_code_08 ('268 ', '269', ' 270')

    OR rcresar_comm_code_09 ('268 ', '269', ' 270')

    OR rcresar_comm_code_10 ('268 ', '269', ' 270'))


    Rcresar_aidy_code = & aidy_code

    AND rcrapp1_aidy_code = rcresar_aidy_code

    AND rcrapp1_curr_rec_ind = 'Y '.

    AND rcrapp1_seq_no = rcresar_seq_no


    AND spriden_pidm = rcresar_pidm

    AND rcrapp1_pidm = rcresar_pidm


    AND spriden_change_ind IS NULL

    ORDER BY name


    The second case statement is where I don't know exactly what it takes to get what I want.

    Output should be like:
    spriden_pidm name ID acg_elig_comm_code comm_code_description
    «0000000000', ' 1111111111 ","John Doe","268", «rigorous HS race"»

    If I take the second case statement it works great except that I do not have my comm_code description column. My question is how can I use my first statement value box to determine this column? I think that I need a case statement as I have, but I don't know how to reference the value of acg_elig_comm_code. Any help would be greatly appreciated. Thank you.

    Published by: blackhole82 on January 20, 2009 09:20

    Hello

    You cannot use the alias column in the query, even where it is set (except in the ORDER BY clause).
    You can set the alias in a subquery and then use it in a great query, like this:

    WITH  sub_q  AS
    (
        SELECT DISTINCT spriden_pidm,spriden_id id, spriden_last_name||', '||spriden_first_name name,
            CASE
                WHEN rcresar_comm_code_01 IN ('268','269','270') THEN rcresar_comm_code_01
                WHEN rcresar_comm_code_02 IN ('268','269','270') THEN rcresar_comm_code_02
                WHEN rcresar_comm_code_03 IN ('268','269','270') THEN rcresar_comm_code_03
                WHEN rcresar_comm_code_04 IN ('268','269','270') THEN rcresar_comm_code_04
                WHEN rcresar_comm_code_05 IN ('268','269','270') THEN rcresar_comm_code_05
                WHEN rcresar_comm_code_06 IN ('268','269','270') THEN rcresar_comm_code_06
                WHEN rcresar_comm_code_07 IN ('268','269','270') THEN rcresar_comm_code_07
                WHEN rcresar_comm_code_08 IN ('268','269','270') THEN rcresar_comm_code_08
                WHEN rcresar_comm_code_09 IN ('268','269','270') THEN rcresar_comm_code_09
                WHEN rcresar_comm_code_10 IN ('268','269','270') THEN rcresar_comm_code_10
            END acg_elig_comm_code   -- Originally posted with , here (error)
        FROM spriden, rcresar, rcrapp1
        WHERE (rcresar_comm_code_01 IN ('268','269','270')
                OR rcresar_comm_code_02 IN ('268','269','270')
                OR rcresar_comm_code_03 IN ('268','269','270')
                OR rcresar_comm_code_04 IN ('268','269','270')
                OR rcresar_comm_code_05 IN ('268','269','270')
                OR rcresar_comm_code_06 IN ('268','269','270')
                OR rcresar_comm_code_07 IN ('268','269','270')
                OR rcresar_comm_code_08 IN ('268','269','270')
                OR rcresar_comm_code_09 IN ('268','269','270')
                OR rcresar_comm_code_10 IN ('268','269','270'))
        AND rcresar_aidy_code = &aidy_code
        AND rcrapp1_aidy_code = rcresar_aidy_code
        AND rcrapp1_curr_rec_ind = 'Y'
        AND rcrapp1_seq_no = rcresar_seq_no
        AND spriden_pidm = rcresar_pidm
        AND rcrapp1_pidm = rcresar_pidm
        AND spriden_change_ind IS NULL
    )
    SELECT    sub_q.*,
              CASE
                  WHEN acg_elig_comm_code = '268' THEN 'Rigorous HS course'
                  WHEN acg_elig_comm_code = '269' THEN '2 or more AP or IB'
                  WHEN acg_elig_comm_code = '270' THEN 'ACG possible'
              END comm_code_description
    FROM      sub_q
    ORDER BY  name
    

    Furthermore, you might think to rearrange your table, so that you do not have 10 columns (rcresar_comm_code_01, rcresar_comm_code_02,...) that essentially do the same thing. The usual way to handle this kind of one-to-many relationship is to have all rcresar_comm_codes in a separate table, one per line, with a pointer to the table where you have them now.

    Published by: Frank Kulash, January 20, 2009 11:35
    Syntax error has been corrected

Maybe you are looking for

  • C50-A-1DV satellite makes strange static/buzzing noise

    My brand new toshiba laptop is constantly producing a strange humming/static noise that seems to come from the fan. I don't know if this is the case with all these models but it's pretty boring and I fear that something could be wrong with the laptop

  • Accident of service pack 1

    Windows update downloaded sp1 and now my machine is basically dead. It keeps just restarting at the helm of the Green window. safe mode does not work and my boot drive is not work.when I still use the drive I get a blue screen that says windows is un

  • Audio dev Alpha C Cup using OpenAL

    Hello I have some problem with the audio on my device Dev Alpha C and I was wondering if anyone else has had or similar problems or that he might be able to offer a solution. The problem When you run our game on a device Dev Alpha C, after a short pe

  • 715 HP photosmart digital camera

    I need a drver for Windows 7 compatible with a digital camera of 715 HP photosmart. Help, please!

  • Error code 0 x 80070078 during the installation of the games on the Store

    Original title: Error Code 0 x 80070078 I selected a free application of games from the store, but when I try to install it I get the above error Code...   How can I overcome this. From: http://answers.Microsoft.com/en-us/Windows/Forum/windows_8-wind