Could you help this query

hi to all
i have table called period which has the four columns id(p.key),name,parent_id,level
i have 3 different types of periods for eg
101 2009 null 1
102 Q1 101 2
103 Jan 102 3
so here parent_id is also a period , and have Q1,Q2,Q3,Q4 belong to level 2 and all the months belong to level 3
Q1 has Jan,Feb,March and Q2 has Apr,May,Jun, .... Q4 has Oct,Nov,Dec months as childs
now my question is to show the data for a year 2009 l
displaying 2nd level and immeadetly its sub childs to it like
id              name        level
1096     Q1     2
1097     JAN     3
1098     FEB     3
1099     MAR     3
1100     Q2     2
1101     APR     3
1102     MAY     3
1103     JUN     3
1104     Q3     2
1105     JUL     3
1106     AUG     3
1107     SEP     3
1108     Q4     2
1109     OCT     3
1110     NOV     3
1111     DEC     3
1676     Annual     2( which does not have any more childs but still it is a child of 2009)
1675     N/A     2( which does not have any more childs but still it is a child of 2009)
thanks and regards
santhosh

if I understand correctly this is all bout ordering the data. So we just have to find the correct order by clause.
Since you order by a date the basic principle is to convert all the differnt strings into a date value. Then order on it.
example untested
order by case when level = 3 then to_date(name,'MON')
             when level = 2 and name like 'Q%' then add_months(to_date('0101','ddmm'),(to_number(substr(name,2,1))-1)*3) 
             when level = 2 and name = 'Annual' then to_date('3112','ddmm')
             when level = 2 and name = 'N/A' then to_date('3112','ddmm')
             when level = 1 then to_date('YYYY')
             end,
             levelyou can also create a kind of hierarchical select, but I doubt that this would be faster.
My prefered solution would be to add an additional column of datatype date. Fill it with the correct days and then order on it and on the level.
Btw: With your result data you could order simply on ID, but I doubt if this can be guaranteed. So I do not recommend it.
Edited by: Sven W. on Sep 23, 2009 10:06 AM - corrected level 3 function

Similar Messages

  • HI could you solve this query

    Ex: Table : inputval
    Column: inputvalue VARCHAR2(100)
    DATA for above column are
    TCC=0471/12345/0999/8548/4321,VT=15,PRIMDX=false,DUR=365,VISITS=0
    values termination are '/'
    Q: i need to after TCC value from the inputvalue column
    i need 6 values output are below
    1. 471
    2. 12345
    3. 0999
    4. 8548
    5. 4321
    6. null
    i written query but i am not able to get these output
    i am giving sample query which i tried for one value
    SELECT
    case when inputvalue like '%TCC=%' then
    substr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
    to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
    -to_number(instr(inputvalue,'TCC=')+4)),1,
    instr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
    to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
    -to_number(instr(inputvalue,'TCC=')+4)),'/')-1) end tcc1,
    case when inputvalue like '%TCC=%' then
    substr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
    to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
    -to_number(instr(inputvalue,'TCC=')+4)),
    instr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
    to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
    -to_number(instr(inputvalue,'TCC=')+4)),'/')+1,
    instr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
    to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
    -to_number(instr(inputvalue,'TCC=')+4)),'/',2)-1) end tcc2
    FROM inputval
    please solve me as early as possible
    Thanks,
    krish

    Hi,
    REGEXP_SUBSTR ( s
                  , '[^,]+'
                  , 1
                  , n
                  )returns the nth item in a comma-delimited list s. (It retuirns NULL if there are not that many items.)
    Cross-join with a counter table to get the values for n, and test if the nth item is the one that starts with 'TCC='.
    Depending on you data, it might be easier to use REGEXP_SUBSTR or REGEXP_REPLACE to find the part of the string between 'TCC=' and the next comma. (I can't tell from the one row of sample data.)
    Once you have the TCC-substring, use REGEXP_SUBSTR again to get the m-th item from the /-delimited list. (Use a different counter table.)
    If you need more help, post some more test data and desired results, testing any special cases, such as:
    two or more 'TCC=' items in one string
    NULL entries ('TCC=1///4')
    Misplaced label ('1/2/TCC=3/4/5')
    malformed numbers ('TCC=1.0.0/4')
    REGEXP_ function only work in Oracle 10 and up.

  • TS1453 Hi, I bought Apple tv traying to rent a movie but there problem with itunes, and there is on apple tv don't have my country. could you help me please how can I solve this problem?

    Hi, I bought Apple tv traying to rent a movie but there problem with itunes, and there is on apple tv don't have my country. could you help me please how can I solve this problem?

    Whinston,
    I live in Azerbaijan. Recently I bought apple tv in New York. When I come back to my country tried to rent movies from my country but couldn't find my country name on apple tv menu, so there is a problem I don't know how to fix it. is there have another way to take a rent movies?

  • Right now I changed my ID but when I am trying to update my apps only see this message " Your Apple ID is been desactivated". Could you help me

    Right now I changed my Apple ID but when I am trying to update my apps only see this message " Your Apple ID is been desactivated".
    Could you help me

    This may help:
    http://support.apple.com/kb/ts2446

  • TS3716 My relatively new ipod touch 16 gb either does not show up as a drive or everytime says it does not recognize my ipod when connected to add music.  I didn't have problems loading music originally, but this is a new occurrence.  Could you help?

    My relatively new ipod touch 16 gb either does not show up as a drive or everytime says it does not recognize my ipod when connected to add music.  I didn't have problems loading music originally, but this is a new occurrence.  Could you help?

    Hey, Thanks a lot.  It took quite a bit of time to resurrect this ipod.  I tried the upgrade again, but still would not recognize my ipod. So I went to the next step and reset my ipod, wiping of all of the information like it was new.  This helped my laptop see the ipod on itunes, but did not sync. So, I deleted the itunes off my computer completely, restarted and then reinstalled the newest itunes, and then restarted.  Finally, it recognized my ipod and started to download each song.  It took awhile as there was 602 songs, but finally it works.  Yea!!!  I never had any problem with my old nano, but this touch has been another animal for sure. Thank you again and also the community for information.  This was a helpful forum and will recommend to others if they get stuck with their ipod or iphone.  Take care, Karen

  • Hey sur. my name anas and am from morocco i've just got a new iMac 2011 with OSX 10.7 and i want to downgrade to 10.6 please could you help sur to solve this it

    hey sur. my name anas and am from morocco i've just got a new iMac 2011 with OSX 10.7 and i want to downgrade to 10.6 please could you help sur to solve this it

    anas guellaf wrote:
    it still make 3 bips before starting the IMAC.
    That is another problem not related to the Mac OS X version you are trying to use.
    Three beeps at startup means you have a bad ram module in the computer.  Did you install the ram or did it come from another owner this way?  The first problem you need to solve is the bad ram.
    When the iMac starts, go to the apple left side of the menu bar, About This Mac, More Info, System Report, Hardware, Memory and see what the report is on the memory...does the iMac report all memory modules that have been installed as OK or does it show bad memory?  If there is not any information, you then need to remove the memory modules and restart one at a time to see which is bad.
    On the bottom of the screen there should be a small door that you can remove with a small screw driver.  You need to lay the iMac flat, disconnect the power cord, remove that small door and remove the memory modules.  You can then put two in (if it has four) and see if it starts without the beeps.  Do that with each module so you find out which is bad.  Once you know the bad memory, you can buy a new module, just like the ones installed, so the iMac starts without the beeps.
    Next, you cannot use a DVD for another computer for your iMac unless it is from one that is identical to yours.  So, you need to talk to Apple and have them send the DVD for your particular iMac.

  • Dear Apple Rep,  I have recently transferred purchases I've made on my iPad to my PC.  But the album artwork, while correct on my PC, is all messed up on my iPad--wrong artwork on the many of the albums.    Could you help me in resolving this annoying pr

    Dear Apple Community,
    I have recently transferred purchases I've made on my iPad to my PC.  But the album artwork, while correct on my PC, is all messed up on my iPad--wrong artwork on the many of the albums.  
    Could you help me in resolving this annoying problem?
    Thank you in advance for your assistance,
    Jonathan Treat

    Removed; inapplicable due to date of thread.
    Message was edited by: Dave Sawyer

  • Hi.I need help.my iphone was Stolen .how can I get back my iphone. Serial No.DX*****PMW.could you help me find my iphone.thank you very much.could you send me the ICCID number to help me find the iphone

    Hi.I need help.my iphone was Stolen .how can I get back my iphone.  Serial No.DX******PMW.could you help me find my iphone.thank you very much.could you send me the ICCID number to help me find the iphone.if you can help me.
    <Personal Information Edited by Host>
                                                                                                                                                                   Sincerely a Chinese girl really need your help

    Sorry we are all users on this User  Community No Apple Staff
    Read this .
    http://support.apple.com/kb/HT2526
    Apple do not and cannot assist in finding stolen property ,that is the responsility of your Police

  • For some reason I cannot download and install the latest version of iTunes. 11.0.2. Could you help please? Each time I try, I get a command box saying 'The feature you are trying to download is on a network resource that is unavailable. Click Ok to try ag

    For some reason I cannot download and install the latest version of iTunes. 11.0.2. Could you help please? Each time I try, I get a command box saying 'The feature you are trying to download is on a network resource that is unavailable. Click Ok to try again or enter an alternate path to a folder containing the installation package iTunes.ms in the box below.
    Please help!
    Many thanks in advance
    Ben Bentley
    West Midlands
    UK

    (1) Download the Windows Installer CleanUp utility installer file (msicuu2.exe) from the following Major Geeks page (use one of the links under the "DOWNLOAD LOCATIONS" thingy on the Major Geeks page):
    http://majorgeeks.com/download.php?det=4459
    (2) Doubleclick the msicuu2.exe file and follow the prompts to install the Windows Installer CleanUp utility. (If you're on a Windows Vista or Windows 7 system and you get a Code 800A0046 error message when doubleclicking the msicuu2.exe file, try instead right-clicking on the msicuu2.exe file and selecting "Run as administrator".)
    (3) In your Start menu click All Programs and then click Windows Install Clean Up. The Windows Installer CleanUp utility window appears, listing software that is currently installed on your computer.
    (4) In the list of programs that appears in CleanUp, select any iTunes entries and click "Remove", as per the following screenshot:
    (5) Quit out of CleanUp, restart the PC and try another iTunes install. Does it go through properly this time?

  • When I upgraded my OS to OS X 10.9 the computer doesn't connect the LAN automatically after sleep. Could you help me?

    When I upgraded my OS to OS X 10.9 the computer doesn't connect the LAN automatically after sleep. Could you help me?

    just an update on the situation....
    the problem is solved. after trying everythng, at last i did a reset on my linksys e3200 router - and BANG!!!
    airplay works.
    hope this helps someone else.

  • My iPod has not been working for a month now and i was hoping that you could help me.The part where you charge and sync the iPod is not connecting.There is defiantly not the lead as we use it for the iPhone and that works please could you help!

    my iPod has not been working for a month now and i was hoping that you could help me.The part where you charge and sync the iPod is not connecting.There is defiantly not the lead as we use it for the iPhone and that works please could you help!
    yours sincerly
    jackfromsurrey

    What I am saying is ..........
    The iPhone HAS to be active making calls on the UK carrier network for the carrier to identify as "theirs" and therefore eligible for the Carrier to unlock
    The way to achieve this is to use a PAYG sim making and receiving calls to establish a customer relationship  with the Carrier and then follow the Carrier's process to unlock
    With a PAYG it usually means adding a specified (by the carrier ) amount  usually £15 /£20 depending on the carrier
    This is how O2 function and according to Gemma  this is how Vodafone work

  • I moved to new house where I have wifi base station I made extension via TP-link power line adapter and connect my Airport utility 6.3.2, but I don't now how to set up as a second network with one IP address?Could you help me please?

    I moved to new house where I have wifi base station I made extension via TP-link power line adapter and connect my Airport utility 6.3.2, but I don't now how to set up as a second network with one IP address?Could you help me please?

    Urvergessen wrote:
    +You may have already done this, but do you have the first AirPort Express configured to "Allow this network to be extended"?+
    Could not find that setting anywhere.
    It's in AirPort Utility, AirPort panel, Wireless tab.
    When I'm within the range of the base station I connect normally, but further away the connection drops despite the fact that the other Airport is very close and light is green. Interestingly, my PB Pro has signal almost everywhere in the house, but my iPhone and Mac Mini don't. Most likely just a hardware difference?
    In AirPort Utility with the second Express, in the AirPort panel, Wireless tab, have you checked "Allow wireless clients"?
    The second AP does show an IP address: 10.0.1.3.
    With a "Configure IPv4" setting of "Using DHCP", that suggests that the second Express really is connecting to the first Express. In that case I have no other explanation of your your problem.

  • Apple Mobile Device USB Driver is listed in device manager, but has a yellow  "!".  I try reinstall,disable,enable the drivers but the problem persist. Could you help me ?

    Hi
    I connect my ipad to my pc (Windows xp SP3) and I can see my ipad and photos in my computer. When I install the itunes 11 , after installation , I can't connect the ipad again or any other apple device. The Apple Mobile Device USB Driver is listed in device manager, but has a yellow  "!".
    I have try to reinstall the drivers from c:\progamfiles\common files\apple\... but the problem persist. Could you help anyone about this ?

    You need to completely uninstall iTunes from your computer and then download and install it again.
    You do know that Microsoft has a web site, right?

  • Regarding replacement path.. Could you help me please .. ?

    Dear all,
    I have problem when i use variable replacement path, where it replace another variable.
    The scenario is like this:
    I have variable cal. month user input where the type is interval (let say it's called var A).
    Then i create rep. path variable cal. month:
    1. Replace with : Key
    2. Use Interval : From Value.
    I use this rep. path variable for restricted KF.
    When i run the report:
    I fill in the value for Var A:
    01.2003 - 05.2003
    The invalid things are:
    1. Rep. Path variable only get the value 01.2003. The impact the KF is only restricted by 01.2003.
    It supposed to be restricted by 01.2003, 02.2003, 03.2003, 04.2003.05.2003.
    The questions are:
    1. How can i overcome this problem?
    2. How should i do, if i want to use replacement path in restricted KF that can restrict by 01.2003, 02..2003, 03.2003, 04.2003, 05.2003 ???
    Could you help me to suggest what i should do please .. ?
    Really need your guidances....
    Regards,
    Niel.

    Hi Niel,
    When you use a variable(v1) of processing type replacement path and try to replace it wih another variable the replacement is only by single value. This you can find by details tab in the variable(v1) being created.
    Hence you have only options of replacing it wih from value/ to value/ difference.
    I didn't undersand why you wish to use variable(v1) wih processing type replacement path when you could have used the input variable type for restriction of the characteristic in the restricted key figure.
    I think for your requirement variable processing by manual input is more suitable unless you have some reason for replacement which I didn't undestand.
    Thanks and regards,
    Sunmit.

  • From Sweeden - could you help me please ( i've tryed to do that for almost one day)

    i thing i have aloop problem, could you help me please. i trying to do if user not put in correct value (number instead of a letter or vice versa ) how can the program go back to first menu ( i have been studying for 3 weeks)
        enter code here
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace @break
        class Program
            static void Main(string[] args)
                //Meny
                Console.WriteLine("\n HÄNGA GUBBE\n");
                Console.WriteLine(" 1) Lägg till ord");
                Console.WriteLine(" 2) Lista alla ord");
                Console.WriteLine(" 3) Spela");
                Console.WriteLine(" 4) Avsluta");
                int Valet;
                Console.Write("\n\tVälj 1-4:  ");
                Valet = int.Parse(Console.ReadLine());
                switch (Valet)
                    case 1:
                        Console.WriteLine("\n lägg ett till ord! ");
                        break;
                    case 2:
                         Console.WriteLine("\n Lista med alla ord :\n");
                         string[] array = { " Lev", " Skratta", " Gledje", " Gråt", " Njut" };
                         Array.Sort<string>(array);
                         foreach (var c in array)
                             Console.WriteLine(c);
                         Console.WriteLine("\n");
                         break;
                    case 3:
                        string guesses, bokstäver;
                        Console.Write("\n Hur många fel får man ha? ");
                        guesses = (Console.ReadLine());
                        Console.WriteLine(" Utmärkt, då spelar vi!\n");
                        Console.WriteLine(" Felgisningar :" + "0/" + guesses);
                        Console.Write(" Gissade bokstäver " );
                        bokstäver = (Console.ReadLine());
                        Console.WriteLine("Aktuellt ord");
                        Console.Write("Gissa bokstav : "+bokstäver+" \n");
                        break;
                    case 4:
                        Console.WriteLine("\n  HEJ DÅ! \n");
                        Console.Beep();
                        break;
                    //avbryter while loopen, avslutar spelet
                  

    What do you mean by "lots of problem"? The code I posted certainly compiles and runs just fine. Copy the following code into your Program.cs file in Visual Studio and run it and you will see that it works:
    using System;
    namespace ConsoleApplication1
    class Program
    static void Main(string[] args)
    //Meny
    Console.WriteLine("\n HÄNGA GUBBE\n");
    Console.WriteLine(" 1) Lägg till ord");
    Console.WriteLine(" 2) Lista alla ord");
    Console.WriteLine(" 3) Spela");
    Console.WriteLine(" 4) Avsluta");
    bool exit = false;
    do
    int Valet;
    Console.Write("\n\tVälj 1-4: ");
    try
    Valet = int.Parse(Console.ReadLine());
    catch (Exception)
    Console.WriteLine("Error....!");
    continue;
    switch (Valet)
    case 1:
    Console.WriteLine("\n lägg ett till ord! ");
    break;
    case 2:
    Console.WriteLine("\n Lista med alla ord :\n");
    string[] array = { " Lev", " Skratta", " Gledje", " Gråt", " Njut" };
    Array.Sort<string>(array);
    foreach (var c in array)
    Console.WriteLine(c);
    Console.WriteLine("\n");
    break;
    case 3:
    string guesses, bokstäver;
    Console.Write("\n Hur många fel får man ha? ");
    guesses = (Console.ReadLine());
    Console.WriteLine(" Utmärkt, då spelar vi!\n");
    Console.WriteLine(" Felgisningar :" + "0/" + guesses);
    Console.Write(" Gissade bokstäver ");
    bokstäver = (Console.ReadLine());
    Console.WriteLine("Aktuellt ord");
    Console.Write("Gissa bokstav : " + bokstäver + " \n");
    break;
    case 4:
    Console.WriteLine("\n HEJ DÅ! \n");
    Console.Beep();
    exit = true;
    break;
    //avbryter while loopen, avslutar spelet
    } while (!exit);
    If you can't get this to work despite someone actually giving the exact code you should probably ask some developer to help you.
    If you have some logical issues in your code that's another issue. Please start a new thread if you have a new question.
    Note that the forums are not for anyone else to write an entire application or class for you though :)
    Please remember to close your threads by marking helpful posts as answer.

Maybe you are looking for

  • Receiving a Alert stating that it could not initialize the security component

    The complete Alert announcement. Foxfire will load but will not access the internet. My Explorer browser and email does work. Could not initialize the application's security component. The most likely cause is problems with files in your application'

  • Using a Samsung SyncMaster T220 1680X1050 resolution monitor

    Whenever I try using the above external monitor at the listed native resolution, my Macbook displays it for a split second before becoming a black screen. All of the lower resolutions listed in the Display PreferencePane work, but it's blurry and not

  • Displayport to hdmi to TV.  No Sound

    Using a Displayport to HDMI connector and HDMI cable to connect  my MacBook Air to a TV. I Can twin the displays in Preferences, but no sound from the television.

  • Spry Submenus Rolling Up in Multiple Broswers

    Hi! I'm trying to implement the spry menu on a website but it wont work for me. When you hover over the submenus they flicker and a submenu disappers. Here's a link to a page with this happening: http://celebrationsphotography.us/contact_test.html Th

  • Automatically display the Interactive Scripting on WinClient's CIC

    Is it possible to automatically display the Interactive Scripting for the cic Agent? I only have one script so there's really no need for the agent to choose when he only has that option. I'm on CRM 4. Thanks in advance, V