Flexible Criteria Search?

Greetings
I contsructed a form that allows the user to search up to five criteria:
Date range,
appraiser,
order status,
client
priority
I've attempted to set the action page:
<cfquery name="search_flexible_criteria" datasource="#Request.BaseDSN#">
SELECT order_ID, order_number, order_client_ID, order_rush_status_ID, main_orders.order_status_ID, order_appraiser_ID, order_create_date, order_property_street, order_property_city, client_ID, client_company, appraiser_ID, appraiser_fname, appraiser_lname, lookup_order_status.order_status_ID, order_status, rush_status_ID, rush_status
FROM  main_orders MO, lookup_clients LC, lookup_appraisers LA, lookup_order_status LS, lookup_rush_status LR
WHERE 1 = 1
<cfif IsDefined("Form.StartDate")>
<cfset Session.StartDate = "#CreateODBCDate(FORM.StartDate)#">
<cfset Session.EndDate = "#CreateODBCDate(FORM.EndDate)#">
AND (order_create_date BETWEEN #Session.StartDate# AND #Session.EndDate#)</cfif>
<cfif IsDefined("Form.order_client_ID") AND Form.order_client_ID NEQ 0>
AND    client_ID  = #Form.order_client_ID# </cfif>
<cfif IsDefined("Form.order_appraiser_ID") AND Form.order_appraiser_ID NEQ 0>
  AND  appraiser_ID  = #Form.order_appraiser_ID#</cfif>
<cfif IsDefined("Form.order_status_ID") AND Form.order_status_ID NEQ 0>
   AND   MO.order_status_ID = #Form.order_status_ID#
   </cfif>
<cfif IsDefined("Form.order_rush_status_ID") AND Form.order_rush_status_ID NEQ 0>
    AND  rush_status_ID = #Form.order_rush_status_ID#
    </cfif>
ORDER BY order_create_date DESC
</cfquery>  
The first error encountered is "AND  rush_status_ID = #Form.order_rush_status_ID#"
Not yet got this to work- any advice would be greatly appreciated.
Thanks
seasonedweb

Carl:
Thanks so much for your help (and patience).
Run without a form search, the page now returns all records. But when using the form,
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near ','.
The error occurred in C:/inetpub/wwwroot/appraiseri/admin/reports/reports_multiple_search_action.cfm: line 99
97 : <cfif StructKeyExists(Form, "order_rush_status_ID") AND Form.order_rush_status_ID NEQ 0> 98 : 99 : AND order_rush_status_ID = #Form.order_rush_status_ID#</cfif> 100 : 101 : ORDER BY order_create_date DESC
VENDORERRORCODE
  102
SQLSTATE
  HY000
SQL
   SELECT mo.order_ID, mo.order_number, mo.order_property_type_ID, mo.order_order_type_ID, mo.order_report_type_ID, mo.order_client_ID, mo.order_appraiser_ID, mo.order_status_ID, mo.order_rush_status_ID, mo.order_property_street, mo.order_property_city, mo.order_create_date, ls.order_status_ID, ls.order_status, lc.client_ID, lc.client_company, la.appraiser_ID, la.appraiser_fname, la.appraiser_lname, lo.order_type_ID, lo.order_type, lp.property_type_ID, lp.property_type, lr.report_type_ID, lr.report_type, lrs.rush_status_ID, lrs.rush_status FROM main_orders mo LEFT JOIN lookup_order_status ls ON mo.order_status_ID = ls.order_status_ID LEFT JOIN lookup_clients lc ON mo.order_client_ID = lc.client_ID LEFT JOIN lookup_appraisers la ON mo.order_appraiser_ID = la.appraiser_ID LEFT JOIN lookup_order_type lo ON mo.order_order_type_ID = lo.order_type_ID LEFT JOIN lookup_property_type lp ON mo.order_property_type_ID = lp.property_type_ID LEFT JOIN lookup_report_type lr ON mo.order_report_type_ID = lr.report_type_ID LEFT JOIN lookup_rush_status lrs ON mo.order_rush_status_ID = lrs.rush_status_ID WHERE 1 = 1 AND appraiser_ID = 0,0 AND mo.order_status_ID = 10 ORDER BY order_create_date DESC
DATASOURCE
  appraiseriSQL
Resources:
Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.
Browser 
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
Remote Address 
127.0.0.1
Referrer 
http://127.0.0.1/appraiseri/admin/reports/reports_multiple_search.cfm
Date/Time 
25-Nov-13 08:03 PM
Stack Trace (click to expand)
at cfreports_multiple_search_action2ecfm1645272818.runPage(C:/inetpub/wwwroot/appraiseri/adm in/reports/reports_multiple_search_action.cfm:99) at cfreports_multiple_search_action2ecfm1645272818.runPage(C:/inetpub/wwwroot/appraiseri/adm in/reports/reports_multiple_search_action.cfm:99)
java.sql.SQLException: [Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near ','. at macromedia.jdbc.sqlserverbase.ddca.b(Unknown Source) at macromedia.jdbc.sqlserverbase.ddca.a(Unknown Source) at macromedia.jdbc.sqlserverbase.ddb9.b(Unknown Source) at macromedia.jdbc.sqlserverbase.ddb9.a(Unknown Source) at macromedia.jdbc.sqlserver.tds.ddr.v(Unknown Source) at macromedia.jdbc.sqlserver.tds.ddr.a(Unknown Source) at macromedia.jdbc.sqlserver.tds.ddr.a(Unknown Source) at macromedia.jdbc.sqlserver.ddj.m(Unknown Source) at macromedia.jdbc.sqlserverbase.ddel.e(Unknown Source) at macromedia.jdbc.sqlserverbase.ddel.a(Unknown Source) at macromedia.jdbc.sqlserverbase.ddel.v(Unknown Source) at macromedia.jdbc.sqlserverbase.ddel.r(Unknown Source) at macromedia.jdbc.sqlserverbase.ddel.execute(Unknown Source) at coldfusion.server.j2ee.sql.JRunStatement.execute(JRunStatement.java:359) at coldfusion.sql.Executive.executeQuery(Executive.java:1442) at coldfusion.sql.Executive.executeQuery(Executive.java:1201) at coldfusion.sql.Executive.executeQuery(Executive.java:1131) at coldfusion.sql.SqlImpl.execute(SqlImpl.java:406) at coldfusion.tagext.sql.QueryTag.executeQuery(QueryTag.java:1056) at coldfusion.tagext.sql.QueryTag.doEndTag(QueryTag.java:685) at cfreports_multiple_search_action2ecfm1645272818.runPage(C:\inetpub\wwwroot\appraiseri\admin\reports\reports_multiple_search_action.cfm:99) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:244) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:444) at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65) at coldfusion.filter.IpFilter.invoke(IpFilter.java:64) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:443) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:112) at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62) at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:151) at coldfusion.CfmServlet.service(CfmServlet.java:204) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:414) at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:203) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662)

Similar Messages

  • Multiple criteria search with 4 dropdown lists

    I want to perform a multiple criteria search on a MySQL
    database. Users should be able to use from 4 dropdown lists in a
    form only one criterium, all 4 of them or 2 or 3.
    Each used dropdown list gives a numeric variable: Fvar1 ...
    Fvar4. The variables from the dropdown lists used should be matched
    with numeric fields in the database: DBvar1...DBvar4
    The numeric variables from the dropdown lists that are not
    used, should be ignored.
    Example: a user selects a value in dropdown list 2 and 3 and
    does not use dropdown lists 1 and 4. Fvar1 and Fvar 4 should then
    be ignored for the search, that has to be performed with Fvar2 and
    Fvar3, who have to be matched with DBvar2 and DBvar3.
    Anyone who can help me out with the WHERE statement in my SQL
    query?
    Your help will be greatly appreciated.
    Erik

    Erik61 wrote:
    > I want to perform a multiple criteria search on a MySQL
    database. Users should
    > be able to use from 4 dropdown lists in a form only one
    criterium, all 4 of
    > them or 2 or 3.
    Start by using the Advanced Recordset dialog box to create a
    query that
    looks for all four variables. Then switch to Code view and
    start carving
    up the code created by Dreamweaver.
    The query will look something like this:
    $query_getProducts = sprintf("SELECT product_name, price
    FROM products
    WHERE prod_type = %s AND colour = %s AND size = %s AND range
    = %s
    ORDER BY price ASC",
    GetSQLValueString($var1_getProducts, "text"),
    GetSQLValueString($var2_getProducts, "text"),
    GetSQLValueString($var3_getProducts, "text"),
    GetSQLValueString($var4_getProducts, "text"));
    Change it like this:
    $query_getProducts = "SELECT product_name, price
    FROM products
    WHERE ";
    $where = false;
    if (!empty($_GET['prod_type')) {
    $query_getProducts .= sprintf("prod_type = %s ",
    GetSQLValueString($var1_getProducts, "text"));
    $where = true;
    if (!empty($_GET['colour'])) {
    if ($where) {
    $query_getProducts .= 'AND ';
    $query_getProducts .= sprintf('colour = %s ',
    GetSQLValueString($var2_getProducts, "text"));
    $where = true;
    if (!empty($_GET['size'])) {
    if ($where) {
    $query_getProducts .= 'AND ';
    $query_getProducts .= sprintf('size = %s ',
    GetSQLValueString($var3_getProducts, "text"));
    $where = true;
    if (!empty($_GET['range'])) {
    if ($where) {
    $query_getProducts .= 'AND ';
    $query_getProducts .= sprintf('range = %s',
    GetSQLValueString($var4_getProducts, "text"));
    That builds the query in stages using $where to decide
    whether to add
    "AND" in front of the second, third, and fourth variables.
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • Conditional Criteria Search

    I have a form which uses Get to post fields to another page
    which list real esate results.
    the form works fine it searches
    Area
    Property Type:
    Min Price: etc by pasing the form fields where I have an sql
    query that processes the results.
    The client wants to add an extra filed for searching a
    reference number field in the smae form which if entered will mean
    the search only returns the reference number and nothing else.
    How do I do this in DW
    this is my exsisting sql code for the search of the existing
    fileds
    SELECT *
    FROM Proeprt
    WHERE Price BETWEEN Varmax AND VarMin AND Areaname LIKE
    Varareasort AND types.PropertyType LIKE VarTypes AND Bedrooms LIKE
    VarBeds
    Regards
    Andrew Newton

    My first name is Madhu. The content of the last post changed but the problem did'nt change.
    I don't know if this would make any difference, but one thing I wanted to mention is that, I make my query in a package in the backend and create 15 collections using htmldb_collection.create_collection_from_query and actually return the query
    select c001,c002, c003,c004,c005,c006,c007,c008,c009,c010,c011,c012,c013 from htmldb_collections where collection_name = '''||v_function_name||'''';
    Also, I split my 15 regions into 3 different pages and flow runs perfectly irrespective of how many search criteria entered. But of the main requirements of this application is that, all the regions have to be on one page, unless there is a limitation in APEX.

  • How do I do multiple criteria searches?

    I am so frustrated. When I search in mail I want to be able to type in a keyword ("books") and once those results are up, only look for that search term in emails from or to one person during a certain date range. Any idea if this is possible???

    I think it is probably possible to use logical
    operators
    Yes, that's why I mentioned and-or-not above.
    But back to the poster's question - the search field seems pretty limited, the scenario he described seems to require a Smart Mailbox.

  • Is Safari Find function flexible? (Search for inner strings of characters?)

    I'm running 10.6.8 with Safari Version 5.1.7 (6534.57.2). I see that when you search a web page using the Safari Find function, you can only search for the beginnings of words, not for character strings within the words. Is it possible to expand the Find function's capability to search for inner strings of characters?

    use command F or the edit menus to make the page search box visible - click the magnify/arrow icon at the left side of it - choose "contains" or "starts with".

  • How to add one more values in Search Criteria,

    Hi All,
    OAF page Search Criteria :
    Search By "name"only Available already have in the search criteria .we are need to add Description in search criteria .How to add one more filed “Description” in Search Criteria,
    Please Help Me
    Thanks
    Rajavel

    "Set the Search Allowed property to True for any LOV result items you want to present to the user as searchable values. These items are listed in the search poplist the user sees in the LOV window.
    At a minimum you must set the Search Allowed property to True for the the result table item corresponding to the LOV field on the base page.
    This is from the devguide, I suggest you read it once at least if you have started work on the framework.
    Tapash

  • Cappture search button click of a view criteria

    Hi is it possible to capture the click of a view criteria "Search filter". Search button click?
    Also, is it possible to have teh default of a view criteria to be set at "ALL" or "ANY"

    To listen to the search button's click, you can use the ADF JavaScript API. The AF:Query compoment will raise an event of type "query" when the search button is clicked.
    See the first code snippet in the post below:
    http://myadfnotebook.blogspot.com/2011/09/loading-screen-spinner-pop-up-v20.html
    -Jeevan

  • Images not showing up in keyword searches in Bridge CS6

    Using Bridge CS6, I'm dropping in stock photos (JPEG) and tagging them with persistent keywords. When it comes time to do a search, a couple of these images are being skipped in the results. Other images with the same keywords are being returned, but not these few offenders.
    I've tried resetting Bridge and purging the central Cache.
    Any idea why some files would be invisible to the find function?

    I've performed the search using both the search field in the top right corner, and using the Find command.
    I'm searching the proper source folder, searching for "Keywords" "Containing" <search term>
    Matching "any criteria", searching all subfolders and including non-indexed files.
    The problem is, if I have 3 files with a keyword of Cathedral or cathedral — delimited by semicolons — a search for "cathedral" in the above manner will return 2 of those files, but not the third.
    It looks like I have some problem files that appear in the regular Bridge browser window and have viewable, persistent keywords, but won't appear in search results. They open fine, and the keyword metadata is visible in Photoshop. I'm just wondering if anyone else has experienced something similar.
    If it helps, it's an iStock image: iStock_000025903682Small

  • Recruiting problem with the candidate search by trex with questionnaires

    Hi Gurus,
    I am trying to search candidates using trex in recruiting by candidate_questionnaires but the trex does not show any result. How can I solve it?
    When candidates register theirselves on internet, they complete questionnaires that I have added in the apllication wizard.
    But the problem starts when I want to search candidates by the answers that they have complete in this questionnaire. So I select the criteria search candidate questionnaire, then I select the questionnaire and then the answer and I run the searh. I know that the results shown are always about others requisitions and not the one that I am doing the search. But in my case candidates are assigned in other requisition with the same process template so I do not know where is the problem, because other sort of search works fine. This is the only one that it does not work.
    In addition, I have run the report RCF_CHECK_SEARCH_SETTINGS but the result is that all the parameters are fine except that I have not implement the badi HRAHAP00_FOLLOW_UP_SES. May I have to implement?
    Moreover I have seen that when I select the answer to search, any operator (element of selection mask) is assigned but I have read that it is correct because I am using the search profile "int_cand" with the category "candidate_document" that it use in the mask search candidate_questionnaire.
    In conclusion, I don't know how I can solve this problem with trex? Any idea?
    Thanks in advance,
    Juanjo Garcin.

    I've already done it.
    Do you think this will help?
    I doubt that Apple will listen to us. Users with a problem that occurs quite a lot.

  • Can't remove criteria in Find under Keywords, CS6

    I wonder if anyone else has this problem.  I just recently started using CS6.  This bug is regarding the find "Find" function in my Keywords collection, for example, find everything with Keywords "child".  Adding criteria works wonders, except that once you add it you can no longer remove it.  I attached a screenshot to demonstrate.  After performing a 2-criteria search, I could not remove the second criteria when I perform a new search.  The "minus" button doesn't work.  I tried the "plus" button and it worked, and now i'm stuck with 3 criteria!  I can't leave the fields blank because I get an error message asking me to fill every field out.
    I tired rebooting and purging the cache, and nothing works.  Anyone experienced this or has a solution I can try?

    Curt Y wrote:
    This is not a bug.  You are the only one with it as far as I have seen.  Have Win 7 and tested it and it works perfectly.  I just updated and the new version works as well.  You have not said what OS you use.  What version of CS6 Bridge are you using?
    So there is some program interfering with Bridge, or you have a bad install.  Are the minus buttons greyed out?  Can not tell in the screenshot.
    I'm curious if you tried "Find" under the "Keywords" section.  I don't have this problem when I perform a regular search (e.g. by pressing command + F or control + F). This only happens when I right click on a keyword and find pictures that contain the keyword.
    Very peculiar, but I wouldn't be too surprised if they only tested the regular search function and overlooked the right click keyword search function.
    Obviously I can just do regarlar search from now on, but it's one more step to type in the keyword I want, as opposed to just right click on the keyword.

  • RichQuery Component - not saving criteria while Saving Preference

    I am using RichQuery component to advantage of saving preferences and picking them to execute it once saved. Using the out-of-box component with no customization.
    Criteria values are not as part of saving preferences.
    Ex. Ran the page, then enter criteria like employee name and then hit search button. It displays the result. Now saving preference using save button. I am thinking employee name(what i entered) will be saving as part of perference. Does this save criteria values? Somehow not saving it. Can anyone help me fixing this problem.
    Thanks

    Yes, I am using ADF BC viewcriteria for creating query component. Please try the sample from the below link
    http://andrejusb-samples.blogspot.com/2008/11/jdevadf-sample-adf-query-component-and.html
    Run the main.jspx file -> enter some criteria -> search -> then save -> give a name -> select the criteria from the dropdown.
    Thanks

  • Reg:Search inOAF

    Hi All,
    I am new to OAF,i want to know below details
    1.resultBasedSearch
    2.auto customization criteria
    At what scenerio i have to use?
    and also
    1.Table
    2.AdvancedTable
    i gone through these detail in OAF Developer Guide but could't understand that detail(i need more detail on that concept)
    Regards
    Dillibabu.B

    Hi Dillibabu
    1 ) resultBasedSearch
    Results based search generates search items automatically based on the columns on the results table.
    Eg : simple search is an result based search
    The search regions automatically include both a Go and a Clear button.
    OA Framework automatically executes the underlying search when the user selects the Go button.
    2) auto customization criteria
    In Autocustomization search we need to set what all fields are required to display as a search criteria.
    Eg : Lov search is an Auto customization criteria search .
    OA Framework automatically renders both the Simple and Advanced search regions based on the corresponding Simple search and Advanced search regions that you define and specify as named children of the query region.The search regions automatically include a Go button. In addition, the Advanced search region includes a Clear button.
    OA Framework automatically executes the underlying search when the user selects the Go button. However, developers must explicitly define mappings between items in the Search panel and items in the table region.
    Table : Displays the rows returns by view object in tabular format .
    Advance table : has more feature like :
    1 ) column branding
    2 ) Row branding
    3 ) Column retotalling
    4 ) Add another row
    5 ) Show / Hide region
    Advance table are useful when you want to achieve Master details screens .
    Regards ,
    Keerthi
    Edited by: keerthioaf on Nov 7, 2012 3:48 AM
    Edited by: keerthioaf on Nov 7, 2012 3:50 AM

  • Filter Function for Contacts.app

    Apple Contacts.app needs to be able to filter contacts with more flexible criteria.
    I have maybe hundreds of useless contacts synced from Gmail. Neither Apple Contacts nor Google Contacts offers an ability to filter contacts with following criteria:
    - have phone number but no email
    - have email but no phone number
    - have name but neither phone number nor email
    - don't have name but both name and phone number
    These filters seems impossible to achieve through the existing keyword search. (Maybe with "@" ?) and these would help organize my contacts dramatically more efficiently. For example:
    - I would delete all contacts without either an email nor a phone number
    - I would categorize all contacts without phone numbers into a group
    - I would name all contacts with both name and phone number
    Therefore, this improvement would be very useful.

    > This is a continuation of a previous issue I've been working on. This
    > falls into the realm of filters, so I thought I'd move it here.
    The same sysops cover all the BM forums, therefore it doesn't matter.
    > I have a
    > java app that needs to connect to the internet. It works fine when I
    > unload ipflt. Using filter debug, it seems as if packets are going out
    > correctly, but are being dropped coming back. I thought, that with dynamic
    > NAT, I wouldn't have to create an inbound exception. Am I off base with that?
    Is the exception you made STATEFUL? If it's not stateful the return
    packets will be dropped.
    Cat
    NSC Volunteer Sysop

  • Report for extracting the Expiratin date of the material

    Hi gurus,
    Is there any way We can extract the list of materials with SLED?
    Any standard T code?
    Regards
    Shashi

    Hi Sashi,
    First of I assumes that your materials are Batch Managed.
    Now go to any any of the Transaction where you can execute the report using option of Batch Field.
    For Example MB52, MB51.Go to To MB52 go to Batch Field. Press F4 and use selection criteria
    *Search for Batches with Expiry Date*
    Select required Field like Plant , Material etc and enter you will find list of Materials with Batches and its Expiry Date.
    And if you want to download it then just press right key of mouse, you will find the option for Download this report.
    Regards.
    Dhaval

  • Best way to group data and show details of only last result in group

    Hi All! First off, just letting everyone know that this is a great place to explore and learn Oracle - I've learned more here than I have in some classes. Just exploring the forums and searching for an answer leads me to functions that I hadn't otherwise known existed.
    Here's what I'm looking to accomplish now... let's say I have a table that holds family information - if two or more persons are related in a family (determined by a separate table) then it should return the person identification and then the details of the group.
    For instance, the following data is contained in two tables, the current result follow and then the result I'm looking for...
    PERSONS TABLE
    PERSON         PERSON_ID           ADDRESS
    John Smith     101                     1 Oracle Drive
    Jane Smith     102                     1 Oracle Drive
    RELATIONSHIPS TABLE
    PERSON_ID      RELATEDPERSON_ID
    101                 102
    102                 101A simple query would result in the following:
    WITH PERSONS AS
      SELECT 'John Smith' AS person, 101 AS person_id, '101 Oracle Drive' AS address FROM dual union all
      SELECT 'Jane Smith', 102, '101 Oracle Drive' FROM dual
    ,    RELATIONSHIPS AS
      SELECT 101 AS person_id, 102 AS relatedperson_id FROM dual union all
      SELECT 102, 101 FROM dual
    SELECT
        person
      , address
    FROM  PERSONS p
    JOIN  RELATIONSHIPS r ON r.person_id = p.person_idRESULT
    PERSON      ADDRESS
    John Smith      101 Oracle Drive
    Jane Smith      101 Oracle DriveI'm looking to generate the following result but I'm not sure how to accomplish this... I'm confident it's something simple.
    DESIRED RESULT
    PERSON      ADDRESS
    John Smith     
    Jane Smith      101 Oracle DriveNotice that the address for the related family members is not displayed until the last family member is returned. It would repeat this process for each family.
    Thanks everyone for any help you can provide! 11g
    Edited by: nage62587 on Oct 16, 2012 8:20 PM

    Hi,
    nage62587 wrote:
    I've done a lot of forum searching and revised my question a bit to hopefully make things a bit clearer... I've taken a query Frank wrote and revised to meet my criteria; Searching the forum (and other places on the web) is great! Not only do you find things yourself, but people on this forum are more likely to help you when they see that you're doing all you can.
    If you find something that you try to adapt, post a link to it. Seeing the correct way to adapt it can be very instructive.
    essentially, if I can determine what relatives a person has, then I can create a unique "FAMILY_ID" for them - once I have that, it would appear as though I could then use the FAMILY_ID to group their addresses and other info together.
    The problem I'm having is that if a RELATEDPERSON_ID is linked to a PERSON_ID (PERSON_ID linked to RELATEDPERSON_ID works great), it assigns them a new FAMILY_ID rather than including them into the correct family.
    Here's my sql
    WITH PERSONS AS
    SELECT 'John Smith' AS person, 101 AS person_id, '1 Oracle Drive' AS address FROM dual union all
    SELECT 'Jane Smith', 102, '1 Oracle Drive' FROM dual union all
    SELECT 'Jack Smith', 103, '8 Oracle Drive' FROM dual union all
    SELECT 'John Doe', 104, '10 Oracle Drive' FROM dual union all
    SELECT 'Jane Doe', 105, '10 Oracle Drive' FROM dual union all
    SELECT 'Pete Smith', 106, '1 Oracle Drive' FROM dual
    ,    RELATIONSHIPS AS
    SELECT 101 AS person_id, 102 AS relatedperson_id FROM dual union all
    SELECT 102, 101 FROM dual union all
    SELECT 104, 105 FROM dual union all
    SELECT 105, 104 FROM dual union all
    SELECT 106, 101 FROM dual
    , table_x
    AS
    SELECT   person_id         AS col1
    ,        relatedperson_id  AS col2
    FROM     relationships
    ,     got_relatives     AS
         SELECT     col1
         ,     CONNECT_BY_ROOT col2     AS relative
         FROM     table_x
         CONNECT BY NOCYCLE     col1     =  col2
    OR  col2  =  col1
    SELECT       col1
    ,       DENSE_RANK () OVER ( ORDER BY  MIN (relative)
    ) AS family_id
    FROM      got_relatives
    GROUP BY  col1The result I expect is:
    COL1   FAMILY_ID
    102     1
    106     1
    101     1
    105     2
    104     2
    I suspect that whatever you copied originally had the PRIOR keyword somewhere in the CONNECT BY clause.
    Here's one way to do what you want:
    WITH    all_relationships     AS
         SELECT  person_id
         ,     relatedperson_id
         FROM     relationships
        UNION
         SELECT  relatedperson_id     AS person_id
         ,     person_id          AS relatedperson_id
         FROM     relationships
    ,     got_relatives     AS
         SELECT     CONNECT_BY_ROOT person_id     AS person_id
         ,     relatedperson_id
         FROM     all_relationships
         CONNECT BY NOCYCLE     person_id       = PRIOR relatedperson_id
                 OR          relatedperson_id  = PRIOR person_id
    ,     got_family_id     AS
         SELECT       person_id
         ,       MIN (relatedperson_id)     AS family_id
         ,       ROW_NUMBER () OVER ( PARTITION BY  MIN (relatedperson_id)
                                      ORDER BY          person_id     DESC
                                    )            AS r_num
         FROM       got_relatives
         GROUP BY  person_id
    SELECT       p.person
    ,       CASE
               WHEN  f.r_num  = 1
               THEN  p.address
           END          AS address
    ,       p.person_id
    ,       f.family_id     
    FROM       got_family_id  f
    JOIN       persons      p  ON  p.person_id  = f.person_id
    ORDER BY  family_id
    ,            person_id
    ;Output:
    PERSON     ADDRESS          PERSON_ID  FAMILY_ID
    John Smith                        101        101
    Jane Smith                        102        101
    Pete Smith 1 Oracle Drive         106        101
    John Doe                          104        104
    Jane Doe   10 Oracle Drive        105        104Obviously, you don't have have to display all the columns I displayed above In your first message, you said you wanted only person and address. In your last message, you said you only wanted person_id and family_id. Change the main SELECT clause any way you wish.
    I used the lowest person_id in each family as the family_id. You could use DENSE_RANK if you really wanted to have the families numbered 1, 2, 3, ..., but I suspect you don't really care what family_id is, as long as all the members of the family have the same value.
    You relationship table has some symmetrical relationships, such as
    SELECT 104, 105 FROM dual union all
    SELECT 105, 104 FROM dual union alland some asymmetrical relationships. For example, the only relationship involving person_id=106 is
    SELECT 106, 101 FROM dualthat is, there is no mirror-image row:
    -- SELECT 101, 106 FROM dual union all   -- THIS IS NOT IN THE SAMPLE DATAI assume there is no significance to that. As long as 101 and 106 appear on the same row, they are in the same family, regardless of which is the person_id and which is the relatedperson_id.
    So the first thing I did above was make sure all the mirror-image rows were represented. That's what all_relationships does.
    The next sub-query, got_relatives, is probably what you meant to adapt, but you left off the PRIOR operators.
    Got_family_id actually does the grouping, and also computes r_num to determine which is the last member of the family. Only that family member's address will be displayed in the main query.
    You could combine got_family_id and the main query; you don't really need a sub-query for that. It would be a little less coding, but I wrote it this way because I think it's a little easier to understand and maintain.

Maybe you are looking for

  • My Bill Increased, Promised it would go back down by representative

    I called last month when my bill jumped up $40. I talked to a representative who was very nice and told me my bill was able to go back down to what I was paying. I go and look at my bill for this month and it is $30 higher than she told me it would b

  • Hotmail instead of mac mail

    when i go to a web site and they say contact us,it comes up to send the message through my mac mail.but i want to use my hotmail.how can i change this or is this just the way its going to be.

  • Adobe Premiere Elemens 9 will not start

    Hello, My system is Windows 7. When I want to open a new, or want to start an existing project the programm will not start en I recieve this message: I have uninstalled Premiere Elements 9 and after that installed it again. But the message mentioned

  • Validate Date Input

    Hi, I have 2 input date (date_created and date completed). The date_created column is mandatory but date completed is not. If I enter a value on the date_completed column I want it to be validated against the date_create column. in PL/SQL I can do it

  • Poster frame error in finder icon view

    I've been setting poster frames with control click. While iTunes usually shows the frame I choose, the finder, when in icon view, doesn't. It often picks something close (usually earlier). I usually have to search around to get it to set to the one I