Categories, subcategories and items in one query

Hi,
I have this situation.
I have a category table, a subcategory table and an item
table. The structure is like below:
Category
id_cat..........catname
1...................cat1
2...................cat2
3...................cat3
4...................cat4
Subcategory
id_subcat.......subcatname.......id_cat
1...................subcat1....................1
2...................subcat2....................1
3...................subcat3....................2
4...................subcat4....................3
Items
id_item..........itemname.........id_subcat.......id_cat
1.....................item1.................1.........................1
2.....................item2.................1.........................1
3.....................item3.................2.........................1
4.....................item4.................0.........................2
5.....................item5.................0.........................2
*0 from "id_subcat" in Items table means that the item will
belong directly to the category (and the category won't have
subcategories)
I want to display them like this:
Cat1
...subcat1
.........item1
.........item2
...subcat2
..........item3
...subcat3
Cat2
..........item4
..........item5
Cat3
...subcat4
Cat4
*Cat3 and Cat4 doesn't have any items in it but I still want
to display their names
How can it is possible with CF and SQL? (using SQL server)?
Thank you.

Well...not quite...
It seems the code doesn't work as expected.
It works as expected with the data which already put
there...but if I put new data (like adding a new
category,subcategory and items) it doesn't display as I want it.
So, it may be a problem with bith CF AND SQL...
If I add a new category (and that category won't have
subcategories and items) then it won't be displayed (if I modify
the SQL so the INNER JOIN will become also a LEFT JOIN that new
category gets displayed...but another category dissapears! (and
that category has items in it).
If I add a new subcategory to that new category it won't be
displayed (in both INNER JOIN or LEFT JOIN).
If I let the SQL as it is now (first INNER JOIN and the
second LEFT JOIN) and I add an item to a category I already have
(or subcategory) that item will be displayed in another category
than where it suppose to be (I am adding that item manually and I
check into the database to have the right IDs for categories and
subcategories).
So, I am confused...I don't know what's wrong...
Any other ideas would be helpful, thanks.

Similar Messages

  • Checking and inserting in one query

    Hi,
    I want to check for the existance of a record in a table. If the record is not present then I would like to insert the data.
    I have written a query for this but it is giving me error as ORA-01427: single-row subquery returns more than one row which is true.
    Please help me to rewrite this query. I do not want any procedures etc to apply. Just one query.
    insert into mif_type_temp (FLD_TYPE, FLD_VALUE) values ('SIN', (select b.empname from
    *(select empname from testing tes where not exists*
    *(select 1 from mif_type_temp where tes.empname = FLD_VALUE))b))*
    Thanks

    The VALUES clause can only accept scalar values. Maybe you could try something like this?
    INSERT INTO mif_type_temp
    ( fld_type
    , fld_value
    SELECT 'SIN'
         , empname
    FROM   testing test
    WHERE NOT EXISTS (
                       SELECT 1
                       FROM   mif_type_temp mtt
                       WHERE  test.empname = mtt.fld_value
    ;

  • Need to pull ranked item from one query into new query

    Hi,
    I have a parent query in which I assign a rank to characteristic values based on a key figure, in dollars. I need to pull the top 4 items from that parent query into 4 seperate child queries (i.e. child query 1 is written based on ranked item 1, child query 2 is written based on ranked item 2, etc.) Does anyone have any ideas how to achieve this?
    Thanks
    CM

    Hi,
    I have a parent query in which I assign a rank to characteristic values based on a key figure, in dollars. I need to pull the top 4 items from that parent query into 4 seperate child queries (i.e. child query 1 is written based on ranked item 1, child query 2 is written based on ranked item 2, etc.) Does anyone have any ideas how to achieve this?
    Thanks
    CM

  • Find / replace multiple items in one query

    Hello,
    I need to find and replace several bits of code in dozens of
    files in Dreamweaver CS3. I know how to find/replace for one item
    at a time using regular expressions. Is there a way to find and
    replace more than one item at at time with regular expressions? I
    know I can save and then load previous searches, but that's
    tedious. I'd like to load and then execute more
    Thanks very much for any advice.

    This is in fact the only solution I found to this problem.
    Creating an extension is not that difficult once you have the right
    reference material.
    Have a look at:
    DW API function to find and replace
    http://livedocs.adobe.com/en_US/Dreamweaver/9.0_API/dwr_code_cd_013.html
    Sample extension file on your machine after installing DW
    C:\Program Files\Adobe\Adobe Extension
    Manager\Samples\Dreamweaver\
    Full specifications of the MXI (extension file) format
    http://download.macromedia.com/pub/exchange/mxi_file_format.pdf
    quote:
    Originally posted by:
    Newsgroup User
    > So, is it indeed possible to run more than one
    find/replace query at a
    > time?
    As far as i know, no it's not possible.
    There has been mentions in the past to this question that a
    series of
    find/replace queries could be built as a dw extension instead
    of a saved
    search query.
    Alan
    Adobe Community Expert, dreamweaver

  • Query ESSBASE and Oracle in one query

    What is the best way to query in the same time an ESSBASE database and an Oracle Database.I need to retrieve ESSBASE data with information stored in Oracle Database (supplement data).Thanks

    I've used Oracle and MySQL together on several machines; there's no contention or incompatibility that I've ever encountered. They listen on different ports by default (1521 for Oracle, 3306 for MySQL).
    As for PHP, you'll probably want to read an introductory article from the [Oracle PHP Developer Center|http://www.oracle.com/technology/tech/php/index.html]. Nothing you do there should interfere with your MySQL operations, either.
    Have fun!

  • Use of cost relevant Item categories L2N and G2N for debit and credit memo

    Dear Forum memebers,
    For  credit and debit memo  one of the customised client repot is showing  cost value which is not expected for credit and debit memo in the invoice register.
    This is due to use of L2N and G2N which are cost relevant item categories.
    Why should debit and credit memo item category should be cost relevant.??
    Best Regards,
    Kanwal

    Well if your company do not want to adjust the cost of goods sold when any credit / debit is raised, then yes you can go ahead.
    Thanks
    Sai
    Edited by: Sai on Nov 18, 2009 7:47 PM

  • Framework orders and item categories

    In looking at framework orders it would seem there are 2 item categories that would be valuable for my client, B and D.  In reviewing the configuration, I see the following differences.
    Item cat. B
    Material Required - Not Allowed
    Addit.Acct Assignment - Mandatory
    Inventory Management - Not Allowed
    GR indicator firm - Changeable in PO
    Invoice Receipt - PO Item Linked
    IR indicator - Firmed in PO
    Item cat. D
    Material Required - Not Allowed
    Addit.Acct Assignment - Mandatory
    Inventory Management - Possible
    GR - PO Item Linked
    GR indicator firm - Changeable in PO
    Invoice Receipt - PO Item Linked
    IR indicator - Firmed in PO
    What other differences are there between the two item categories?  I heard that one would default the quantity to 1 and removes the GR... Can anyone validate this?
    Also, I noticed when using a framework order, the validity date is not being checked where the system is allowing invoicing to occur past the validity date.  Is there some place in configuration that we can have this tolerance checked?  Please give details.
    Thank you.
    Nguyen
    Edited by: SCM Supply Chain Management on Sep 5, 2008 7:36 PM

    Hi,
    In case of Item Category B, there is not GR in this case. And in case of Item Category D, you have to create Service Entry Sheet (it is must), which creates a GR document in the background.
    Refer Following links for the above;
    [Blanket Purchase Orders|http://www.sap123.com/showthread.php?t=41]
    [External Service Management|http://www.sap123.com/showthread.php?t=52]

  • PO GR Defaults based on Account *** Cat and Item Categories

    Hi Guys,
    Using the following SPRO path it is possible to set defaults such as if GR is ticked or not, and if it can be changed in the PO based on the account assignment selected in the PO.
    MM - Purchasing - Account Assignment - Maintain Account Assignment Categories
    Using the following SPRO path it is possible to set similar settings based on the item category selected in the PO;
    MM - Purchasing  - Account Assignment - Define External Representation of item Categories.
    How do these settings interact.
    What happens if a combination of Acc Assignment Category and item category have conflicting settings for GR NonVal Firm
    Which ones will SAP use

    Hi,
       For defaulting the GR and IR indicators based on account assignment category, you may use the configuration in OME9 as shown below:
       The item category configuration is not changeable.
       If item category and account assignment category exists, the item category config has the higher priority, as of my knowledge. You may test the same.
    Regards,
    AKPT

  • How do we create a a main podcast category with sub-categories similar to the way many bands have subcategories and artwork for each of their albums?

    How does a content producer create a main category with sub-categories similar to the way many bands have subcategories and artwork for each of their albums?

    I think you're talking about an 'Artist Page' in which several podcasts are 'aggregated' into one iTunes Store page?  This Apple Tech note deals with the subject (scroll to the bottom of the page):
    http://www.apple.com/itunes/podcasts/creatorfaq.html
    Although your mention of albums makes me wonder whether there you are talking about albums and songs in the music Library? - podcasts don't come in albums.
    You've also asked this in another forum:
    I have created a feed for our podcasts, but they are all under one umbrella. We would like to have subcategories under one main category.
    'A feed for your podcasts' doesn't make sense - a podcast has one feed (and vice versa). Are you confusing 'episodes' with 'podcasts'? A podcast is a collection of episodes - you can't categorize the episodes separately. The category shows only on the Store page and applies to the entire podcast. The 'Artist' page may again be what you are aiming for - if not perhaps you could post an example of what someone else is doing that you would like to.

  • Order type, Invoice type and Item categories for Nota Fiscal Brazil

    Hi eveyone,
    we have a company in Brazil implemented in SAP using a different SD Order type, Invoice Type and Item categories
    as our mother company in Switzerland. Reason of that is because of the nota fiscal customization for Brazilian legal requirements.
    We startet with a Project worldwide to rollout a global template within sales and distribution and are facing now exactly
    the problem with those different order type, item categories and Invoice type.
    Our local SAP partner in Brazil told as based on best practise we should have different types.
    I checked the customization and it seems I can't use e.g.: the same Order type for Brazil and Switzerland because
    the activation flag for nota fiscal is linked to the order type and no sales organization can be setted to slplitt the different processes.
    Someone knows if there are some possibilities (maybe trough user exits or badi's) to use globally the same dovument types, item categoreis... globally?
    Thanks in advance
    Gaspare Guttadauro

    Hi Gaspare Guttadauro,
    I would strongly recommend to use the different document types and item categories as suggested by SAP. Since Brazil do have one of the complex taxation process in place hence to determine correct pricing the different document type will be required. Also functionalities  like CFOP determination and nota fiscal relevance can be maintained.
    Please feel free to revert the forum in case of any doubts.
    Cheers
    Atul

  • Difference between Item categories M and W

    What is the difference between the Item Categories ' M ' and ' W ' ?. When & where these item categories are used?

    HI,
    The item categories M and W are intended for the entry of contract items without
    specification of the material number.
    Item category M
    Recommended for similar materials of the same price. These can be materials with
    different material numbers or materials without material master records.
    You have set up a contract with your vendor covering various types of writing
    paper (lined, squared, blank, two-/four-hole prepunched, etc.). The different types
    of paper have the same weight, the same quality, and the same price.
    When entering this contract item of category M, you enter the short description,
    material group, target quantity, unit of measure, and price, but no material number.
    The short description must then be entered in the contract release order (for
    example, lined, two-hole prepunched).
    You also have the option of releasing materials with a material master record
    against this contract item in the release order, provided that the material group and
    purchase order unit of measure agree.
    Item category W
    Recommended for materials belonging to the same material group but with
    different prices. Item category W can only be used in value contracts.
    You have set up a contract with your vendor for various types of cable. The
    contract is to cover all types of cable included in the vendor's price list. However,
    the exact type is only determined when a purchase order is created for a certain
    cable. Instead of creating one contract item for each type of cable in the vendor's
    assortment, you could enter item category W and the appropriate material group
    (for example, cable). From the short text, it would then be clear that the contract
    item covers all types of cable supplied by the vendor in question. Each release
    order issued against this contract would then contain the exact specification of
    cable type and quantity (for example, double-shielded coax, 1 meter), and price.
    When entering the contract item, you enter only the short text and the material
    group. You do not enter the target quantity or price. It is possible to enter
    additional conditions. For example, you can enter a discount in the header
    conditions if the vendor grants a discount on all POs referencing the contract. The
    discount is calculated automatically when a contract release order is created.
    The price, the target quantity, and the material number are not specified until you
    create a release order. The relevant material master record must be assigned to
    the same material group as the contract item referenced. If the contract release
    order does not contain a material number, it must have a valid account assignment
    (such as a cost center).

  • Grouped and non-grouped SELECT in one query: help!

    look first at: Wrong result when I use CASE on this forum. Here I wanted to get the user who created and the user who solved a problem (Lets call it Validation Error from now on (VE)).
    The thing is: I already have a query who returns me lots of information about a VE.
    The query in the previous thread returned me additional info about that VE (that is the creating_user and the solving_user). The 1st query is no group select, but the second is! Still, I need to combine those two in one query.
    1st query:
    select ve.seq,
         max((case vah.action when 'C' then vah.ur_code else null end)) created,
         max((case vah.action when 'S' then vah.ur_code else null end)) solved
    from validation_errors ve
    left outer join ver_action_histories vah
    on (ve.seq = vah.ver_seq AND ve.log_date = vah.ver_log_date)
    where ve.seq = 12860687
    group by ve.seq;Result:
    seq       | created | solved
    12860687    Bob       Bobdont mind the "where"-clause, it is just to make the query go faster
    what I do is: I join the VE with the ver_action_histories table which contains the users and what action they performed on a VE.
    Now I just want to add that information to the results of an other query which also returns lots of information about a VE.
    2nd query:
    select ve.seq "VE seq", mh.seq "Counter seq",
              ve.log_date, ve.solve_date, ve.solved Status, ve.failure_code, ve.mde_code,
              mh.meter_type,
              iv.mr_type, iv.mr_reason,
              ih.mmr_seq
    from validation_errors ve
    inner join meter_histories mh
    on (ve.mhy_seq = mh.seq)
    left outer join index_values iv
    on (ve.mhy_seq = iv.mhy_seq AND ve.log_date =iv.timestamp)
    left outer join index_histories ih
    on (ve.mhy_seq = ih.ive_mhy_seq)
    where ve.seq = 8653936
    and sysdate >= mh.start_date
    and sysdate < mh.end_date;dont mind the "where" and "and"-clauses ... I hope the result of this query will simplify things ...
    Result:
    seq        |   counter seq | log_date | solved_date | status    | failure_code | ...
    12860687       4568          1-jan-06   2-jan-06      Solved      ABCNow the actual question: Is it possible to combine those queries in one query? I just want the results of the first query (creating_user and solving_user) to be added as columns to the second result. Performance is very important. Please tell me that its possible?
    Wanted Result:
    seq        |   counter seq | log_date | solved_date | status    | failure_code | created  | solved  | ...
    12860687       4568          1-jan-06   2-jan-06      Solved      ABC            Bob        BobIf anything I explained is unclear, please tell so I can try to explain it in an easier way.

    Try an in line view:
    select *
    from
    ( <your first query goes here > ) a
    , ( <your second query goes here > ) b
    where a.seq = b.seq

  • Convert data link between one query's group and another querys group to SQL

    Hi
    I have a report where there are 2 query Groups. These 2 query groups r linked by data link. How do i combine these queries to One query so i can use it as a SQL query.
    Thanks

    Hi,
    Assume that we have two queries Q1 and Q2 and the common column between the two queries is "comn".
    Now we can convert the datalink into SQL as follows:-
    SELECT *
    FROM
    (Query for Q1)a,
    (Query for Q2)b
    WHERE a.comn=b.comn(+)
    Note: "a" and "b" are alias names for Q1 and Q2.

  • How I can change this query, so I can display the name and scores in one r

    How I can change this query, so I can add the ID from the table SPRIDEN
    as of now is giving me what I want:
    1,543     A05     24     A01     24     BAC     24     BAE     24     A02     20     BAM     20in one line but I would like to add the id and name that are stored in the table SPRIDEN
    SELECT sortest_pidm,
           max(decode(rn,1,sortest_tesc_code)) tesc_code1,
           max(decode(rn,1,score)) score1,
           max(decode(rn,2,sortest_tesc_code)) tesc_code2,
           max(decode(rn,2,score)) score2,
           max(decode(rn,3,sortest_tesc_code)) tesc_code3,
           max(decode(rn,3,score))  score3,
           max(decode(rn,4,sortest_tesc_code)) tesc_code4,
           max(decode(rn,4,score))  score4,
           max(decode(rn,5,sortest_tesc_code)) tesc_code5,
           max(decode(rn,5,score))  score5,
           max(decode(rn,6,sortest_tesc_code)) tesc_code6,
           max(decode(rn,6,score))  score6        
      FROM (select sortest_pidm,
                   sortest_tesc_code,
                   score,
                  row_number() over (partition by sortest_pidm order by score desc) rn
              FROM (select sortest_pidm,
                           sortest_tesc_code,
                           max(sortest_test_score) score
                      from sortest,SPRIDEN
                      where
                      SPRIDEN_pidm =SORTEST_PIDM
                    AND   sortest_tesc_code in ('A01','BAE','A02','BAM','A05','BAC')
                     and  sortest_pidm is not null 
                    GROUP BY sortest_pidm, sortest_tesc_code))
                    GROUP BY sortest_pidm;
                   

    Hi,
    That depends on whether spriden_pidm is unique, and on what you want for results.
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevamnt columns only) for all tables, and the results you want from that data.
    If you can illustrate your problem using commonly available tables (such as those in the scott or hr schemas) then you don't have to post any sample data; just post the results you want.
    Either way, explain how you get those results from that data.
    Always say which version of Oracle you're using.
    It looks like you're doing something similiar to the following.
    Using the emp and dept tables in the scott schema, produce one row of output per department showing the highest salary in each job, for a given set of jobs:
    DEPTNO DNAME          LOC           JOB_1   SAL_1 JOB_2   SAL_2 JOB_3   SAL_3
        20 RESEARCH       DALLAS        ANALYST  3000 MANAGER  2975 CLERK    1100
        10 ACCOUNTING     NEW YORK      MANAGER  2450 CLERK    1300
        30 SALES          CHICAGO       MANAGER  2850 CLERK     950On each row, the jobs are listed in order by the highest salary.
    This seems to be analagous to what you're doing. The roles played by sortest_pidm, sortest_tesc_code and sortest_test_score in your sortest table are played by deptno, job and sal in the emp table. The roles played by spriden_pidm, id and name in your spriden table are played by deptno, dname and loc in the dept table.
    It sounds like you already have something like the query below, that produces the correct output, except that it does not include the dname and loc columns from the dept table.
    SELECT    deptno
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
               SELECT    deptno
               ,          job
               ,          max_sal
               ,          ROW_NUMBER () OVER ( PARTITION BY  deptno
                                              ORDER BY          max_sal     DESC
                                )         AS rn
               FROM     (
                             SELECT    e.deptno
                       ,           e.job
                       ,           MAX (e.sal)     AS max_sal
                       FROM      scott.emp        e
                       ,           scott.dept   d
                       WHERE     e.deptno        = d.deptno
                       AND           e.job        IN ('ANALYST', 'CLERK', 'MANAGER')
                       GROUP BY  e.deptno
                       ,           e.job
    GROUP BY  deptno
    ;Since dept.deptno is unique, there will only be one dname and one loc for each deptno, so we can change the query by replacing "deptno" with "deptno, dname, loc" throughout the query (except in the join condition, of course):
    SELECT    deptno, dname, loc                    -- Changed
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
               SELECT    deptno, dname, loc          -- Changed
               ,          job
               ,          max_sal
               ,          ROW_NUMBER () OVER ( PARTITION BY  deptno      -- , dname, loc     -- Changed
                                              ORDER BY          max_sal      DESC
                                )         AS rn
               FROM     (
                             SELECT    e.deptno, d.dname, d.loc                    -- Changed
                       ,           e.job
                       ,           MAX (e.sal)     AS max_sal
                       FROM      scott.emp        e
                       ,           scott.dept   d
                       WHERE     e.deptno        = d.deptno
                       AND           e.job        IN ('ANALYST', 'CLERK', 'MANAGER')
                       GROUP BY  e.deptno, d.dname, d.loc                    -- Changed
                       ,           e.job
    GROUP BY  deptno, dname, loc                    -- Changed
    ;Actually, you can keep using just deptno in the analytic PARTITION BY clause. It might be a little more efficient to just use deptno, like I did above, but it won't change the results if you use all 3, if there is only 1 danme and 1 loc per deptno.
    By the way, you don't need so many sub-queries. You're using the inner sub-query to compute the MAX, and the outer sub-query to compute rn. Analytic functions are computed after aggregate fucntions, so you can do both in the same sub-query like this:
    SELECT    deptno, dname, loc
    ,       MAX (DECODE (rn, 1, job))     AS job_1
    ,       MAX (DECODE (rn, 1, max_sal))     AS sal_1
    ,       MAX (DECODE (rn, 2, job))     AS job_2
    ,       MAX (DECODE (rn, 2, max_sal))     AS sal_2
    ,       MAX (DECODE (rn, 3, job))     AS job_3
    ,       MAX (DECODE (rn, 3, max_sal))     AS sal_3
    FROM       (
                   SELECT    e.deptno, d.dname, d.loc
              ,       e.job
              ,       MAX (e.sal)     AS max_sal
              ,       ROW_NUMBER () OVER ( PARTITION BY  e.deptno
                                           ORDER BY       MAX (sal)     DESC
                                          )       AS rn
              FROM      scott.emp    e
              ,       scott.dept   d
              WHERE     e.deptno        = d.deptno
              AND       e.job                IN ('ANALYST', 'CLERK', 'MANAGER')
                  GROUP BY  e.deptno, d.dname, d.loc
              ,       e.job
    GROUP BY  deptno, dname, loc
    ;This will work in Oracle 8.1 and up. In Oracle 11, however, it's better to use the SELECT ... PIVOT feature.

  • Is it possible to add value item and non stock item in one billing?

    Is it possible to add value item and non stock item in one billing?

    Hi,
    Yes,it is possible .Take example of service scenario,where material used in servicing and service charges(labour) can be billed in single invoice.
    Billing document type,Customer and other header data should be same.
    Reward points if useful
    Regards,
    Amrish Purohit

Maybe you are looking for