When to use foreach in a pipeline?

Hello
I keep running into this confusion - when to use foreach cmdlet in a command line and when not to? (Please note I am not talking about foreach loop construct).
For example I have seen the following 2 do not work in the same way:
import-csv input.csv | foreach {
$UserPrincipalName = $_.UserPrincipalName;
Get-ADUser -filter {userprincipalname -eq $userprincipalname} -properties *
| foreach { set-aduser $_ -UserPrincipalName "$($_.samaccountname)@test.local"}
and
import-csv input.csv | foreach {
$UserPrincipalName = $_.UserPrincipalName;
Get-ADUser -filter {userprincipalname -eq $userprincipalname} -properties * |  set-aduser $_ -UserPrincipalName "$($_.samaccountname)@test.local"
The first one above does what I want but not the second one.
Is there any logic to this?

Hi Guys,
I think I got my head straightened out, so here's the best attempt at explaining this:
The basic pipeline
The $_ is the dynamic variable that describes the object currently precessed in the pipeline. However, it only exists within the scope of the currently processing command. An Example:
Get-ExampleObjects | Process-ExampleObjects -ToLower -Description "I'm a new description" | Set-ExampleObjects
Get-ExampleObjects passes its output (whatever it might be) to the pipeline
This output is piped to Process-ExampleObjects, a command that is designed to handle Pipeline Input.
Within Process-ExampleObjects (which is its own scope), the currently processed Pipeline Object is referenced by the variable $_ and can thus be used. HOWEVER: This does not mean it exists within "| Process-ExampleObjects |" but within "Process-ExampleObjects".
This means that while Process-ExampleObjects can have parameters, they need to be static as far as the current pipeline is concerned.
Once Process-ExampleObjects is done, it passes its output via pipeline to Set-ExampleObjects. This moves the object out of the Process-ExampleObjects scope and directly into the Set-ExampleObjects scope within which the current object is again available
in $_.
Adding Scriptblocks
So far, this is 'fairly simple'. As far as this is concerned, you would never see or use $_ at all. However, complexity is added when we add scriptblocks. Let's modify our last pipeline a bit:
Get-ExampleObjects | Process-ExampleObjects -Filter {$_.Name -like "RAS*"} | Set-ExampleObjects
Now, you may think "Hey! Aren't we using $_ as a parameter!?" on the -Filter Parameter of Process-ExampleObjects.
No, we are not.
What we do, is pass a Scriptblock into Process-ExampleObjects. Think of this above line like this:
Get-ExampleObjects | Process-ExampleObjects -Filter [Scriptblock] | Set-ExampleObjects
The scriptblock thing is passed as it is into the Process-ExampleObjects scope of the pipeline, and is applied to the objects while they are within the command. It's similar to passing a static line of text to a function, which means, on the inside "$_"
arrives as it is, not as its value (which after all would still be null).
Static external variables are still read as such and work. This should work:
$string = "RAS*"
Get-ExampleObjects | Process-ExampleObjects -Filter {$_.Name -like $string} | Set-ExampleObjects
The reason this was implemented in such a way is simple: It allows us to dynamically alter the behavior of a function. But for us to be able to do this, we must somehow be able to refer to the input. That's what $_ is for.
Cursed Nesting
Finally what probably messed with your mind the most, we reach nesting pipelines.
An example where it went wrong:
Import-csv input.csv | foreach {$UserPrincipalName = $_.UserPrincipalName;Get-ADUser -filter {userprincipalname -eq $userprincipalname} -properties * | set-aduser -UserPrincipalName "$($_.samaccountname)@test.local"}
is the same as
Import-csv input.csv | foreach [Scriptblock 1]
This means you get the content of input.csv, pass it via the pipeline to the foreach command, which applies the Scriptblock to each of them.
This scriptblock then is this:
# Scriptblock 1
{$UserPrincipalName = $_.UserPrincipalName; Get-ADUser -filter [ScriptBlock 2] -properties * | set-aduser -UserPrincipalName "$($_.samaccountname)@test.local"}
Scriptblock 2 is not an issue and works just fine (though it is its own special case, but not the issue of the matter).
However, here comes the catch:
The "Get-ADUser | Set-ADUser" segment is a nested pipeline, and as far as "$_" is concerned, that's like working with braces in mathematics: Inner brace first.
Which means for all practical purposes, that once you are past the first pipeline symbol ("|") you can no longer refer to the $_ of the outer Scriptblock 1 until the pipeline is finished. However, before you enter Set-ADUser, $_ doesn't hold a value
yet, which is why the UserPrincipalName will be set to "@test.local"
Takeaway notes:
- When creating nested pipelines in scriptblocks, after the first "|" you can no longer refer to the original "$_" of the scriptblock until the nested pipeline concludes.
Cheers and I hope that was more comprehensible,
Fred
There's no place like 127.0.0.1

Similar Messages

  • When to use FOREACH REFDATA?

    Hi,
    I have been trying to research the FOX statemet FOREACH REFDATA.  I have read OSS note 646618 but it's a bit vague.  Can somebody provide more details (real examples with explanations would be great!!) on what this does?  What is the difference between FOREACH REFDATA and FOREACH?  When would I use it?
    Thanks
    Kory

    You use REFDATA when you have set some values at a different level and only read from this data.
    Eg: I have used this when I put Salary Cost drivers at a Controlling Area (Agency) and I want to use copy those rates to each CC, employee. So the Planning level selctions are different.
    DATA FTE_DAY TYPE F.
    FOREACH REFDATA PERIOD,PAREA, PTYPE, VERSION.
    *Capture Agency Specific Leave Rate ie reference data – *Planning Level Z003.
    FTE_DAY =
    {YDATLV,#,#,#,#,#,PERIOD,#,#,#,#,PTYPE,#,#,VERSION,#}.
    Write the Leave Rate to each Employee ie Planning Level *Z012
    {YDATLV,COSTCTR,EMP_GRP,EMPLOYEE,EMP_SGRP,3,PERIOD,
    POSITION,PAREA,PGRP,PLEVEL,PTYPE,PERSONNEL_A,PERSONNEL_S,
    VERSION,FUND} = FTE_DAY.
    This worked well.

  • When I use SSIS for extract from OLAP Database, then the error random occurred,Error Code = 0x80040E05

     I have tired for this!
    When I use SSIS for extract data from ssas, that means,I use mdx query.
    then random error occured.
    Hope some one can understand my poor English....
    And the Error Info show below.
    Code Snippet
    Error: 0xC0202009 at Data Flow Task - For Individual User Tech Points, OLE DB Source 1 1 [31]: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E05.
    An OLE DB record is available.  Source: "Microsoft OLE DB Provider for Analysis Services 2005"  Hresult: 0x00000001  Description: "Error Code = 0x80040E05, External Code = 0x00000000:.".
    Error: 0xC004701A at Data Flow Task - For Individual User Tech Points, DTS.Pipeline: component "OLE DB Source 1 1" (31) failed the pre-execute phase and returned error code 0xC0202009.

    I have had the same error on SQL2008 and now on SQL2012 SSIS, but have been able to eliminate / workaround.
    We have a Loop Container in our Control flow that contains a data-flow task with an MDX source. The MDX query for the data-flow source is dynamically built (via an expression) on each iteration of the Loop container (however it always returns the "same shaped"
    results - only the filters in the WHERE clause are different).
    We've found the error to be somewhat intermittent - sometimes the package will complete successfully, other times it will fail with the 0x80040E05 error at varying iterations thru the container loop.
    To alleviate the problem we setup the SQL Agent job-step for this package to re-try on failure for up to 5 retries - not an ideal workaround, but it helped to improve the success rate of the Job.
    We have no idea why this error is occurring or what is causing it, however it appears to be timing-related in some way and I have only seen the issue when using a SSAS OLE-DB data source with a dynamically generated MDX query. I have managed to virtually
    eliminate the error from occurring with a not ideal workaround in the SSIS package - no idea why this works/helps (hopefully Microsoft will be able to work it out and resolve the issue as it's been plaguing us since SQL2008 and is still here in SQL2012
    SP1...
    Workaround for MDX causing 0x80040E05 error:
    Within our loop container we have added a Script task with OnSuccess precedent constraint to the data-flow task that contains the dynamically generated MDX source query. The script task simply introduces a WAIT in the processing immediately after the
    data-flow task completes of about 5 seconds, before allowing SSIS to continue with the next iteration (e.g. System.Threading.Thread.Sleep(5000)).
    With this delay in place we have had much more stable SSIS package executions - dont know why, but that's what we havce observed. Also note that when we migrated to SQL2012 SSIS packages the 0x80040E05 error returned, however we were able to eliminate it
    once more by increasing the WAIT time to 10 seconds on this script task.
    Now waiting for 10 seconds is not an ideal solution / workaround to this problem - particularly when it is contained within a Loop Container (in our case it has added nearly 30 minutes of "WAIT time" to the package execution duration), however this workaround
    is better than having the package fail 80%+ of the time...
    regards,
    Piquet

  • Please provide real time scenario for when we use object type in PL/SQL.

    Hi Experts,
    When we use this kind of code in PL/SQL block.
    CREATE OR REPLACE TYPE sample_object IS OBJECT
    (id       NUMBER
    ,name     VARCHAR2(30));
    CREATE OR REPLACE TYPE sample_table IS TABLE OF sample_object;I have read some docs ,but I didn't get any information where exactly we use this.
    Please provide one real time scenario with an example.
    How this is different from record.
    Thanks in advance.

    Hi,
    For an example please have a look at this....
    CREATE OR REPLACE TYPE FML_DAT_ITEMS_OBJ AS OBJECT
                      (F_NAME VARCHAR2 (20), L_NAME VARCHAR2 (20));
    CREATE OR REPLACE TYPE FML_DAT_ITEMS_FTAB AS TABLE OF FML_DAT_ITEMS_OBJ;
    CREATE OR REPLACE FUNCTION GET_FML_ITEMS_DAT (PFML_NR IN NUMBER)
       RETURN FML_DAT_ITEMS_FTAB
       PIPELINED
    AS
       OUT_REC   FML_DAT_ITEMS_OBJ;
    BEGIN
       SELECT FML_DAT_ITEMS_OBJ ('peter', 'zwan') INTO OUT_REC FROM DUAL;
       FOR I IN 1 .. PFML_NR
       LOOP
          PIPE ROW (OUT_REC);
       END LOOP;
    END GET_FML_ITEMS_DAT;To view the o/p:
    SELECT * FROM TABLE (get_fml_items_dat (5));
    F_NAME, L_NAME
    peter,zwan
    peter,zwan
    peter,zwan
    peter,zwan
    peter,zwan Refer these links to know more about the topic...
    http://www.oracle-developer.net/display.php?id=207
    http://www.oracle-base.com/articles/misc/pipelined-table-functions.php

  • AVG Secure Search appears when I use Google Search from my Home page only.

    My home page is the Firefox default page with the Google searchbar. I like getting occasional messages from Firefox when I log in so I don't want to change my homepage. However, when I use the searchbar ''on my homepage only'', I get the unsatisfactory AVG Secure Search results.
    UPDATE: I now realize all the troubleshooting information I included in my original question appears under the "More System Details" link next to the question, not in the body of the question. I have copied it here to make it easier to see what I have already done to try to solve the problem, as well as describe the one clue I have that may be relevant:
    I have tried all the fixes on various threads, but my about:config is now pristine (no avg or isearch mentions; keyword.url is default). Closest solution is that at https://support.mozilla.org/en-US/questions/866327 , which requires changing my home page.
    Oddly, AVG Secure Search is ''not'' a problem when I use the Google toolbar or search from the Google website, only when I use the search bar that appears on my home (start) page. This is true even when I return to my home page--if I search from the Google search bar in the middle of the page, I get sent to AVG Safe Search. (isearch.avg.com).
    I read in one thread a suggestion to delete my chromeappsstore.sqlite file in my Profile folder. As promised, Firefox created a new one when I restarted it; however, the search bar in the middle of my home home page did not work at all. Tried this three times before restoring my original.
    I do not have an application that will open a sqlite file, but I tried doing so in Excel and found a cell containing the following:
    emoh.:moz-safe-aboutsearch-engine{"name":"AVG Secure Search","searchUrl":"http://isearch.avg.com/search?cid={7A3C25A0-E345-4507-AA31-D98F596A81A9}&mid=c48135235ba247d18ac1d14b344db451-addd29eab2809954d5abdf0b991a5b911a297819&ds=is015&lang=en&v=10.0.0.7&pr=sa&d=&sap=dsp&q=_searchTerms_"}
    I have no clue what that means, but it is the only thing I can find related to Firefox that still mentions AVG and isearch.avg.com.
    At this point my best guess (but it is a guess) is that the chromeappsstore.sqlite file is a key to the complete solution, but I do not have enough knowledge to go beyond and address it. I appreciate any help you anyone can offer.

    Here is the way to get rid of the problem once and for all:
    http://forums.avg.com/ww-en/avg-forums?sec=thread&act=show&id=196402#post_196402

  • 1)Now I use Lightrom 5.7 how to upgrade to 6 or CC? 2) What is the difference between 6 and CC vercion? 3) When I used lightromm 3, I could see inEXIF the distance in meters till the object I took, in the later virsions that function disappeared, it is ve

    1)Now I use Lightrom 5.7 how to upgrade to 6 or CC?
    2) What is the difference between 6 and CC version?
    3) When I used lightromm 3, I could see in EXIF the distance in meters till the object I took, in the later virsions that function disappeared, it is very sad  I am stiil waiting and hope that it would be possibble in the new  versions. Or this indication may  possible by setting?

    1)Now I use Lightrom 5.7 how to upgrade to 6 or CC?
    Purchase the standalone upgrade from here: Products
    Download CC version from here: Explore Adobe desktop apps | Adobe Creative Cloud
    2) What is the difference between 6 and CC version?
    See this comparison chart: Compare Lightroom versions | Adobe Photoshop Lightroom CC
    3) When I used lightromm 3, I could see in EXIF the distance in meters till the object I took, in the later virsions that function disappeared, it is very sad  I am stiil waiting and hope that it would be possibble in the new  versions. Or this indication may  possible by setting?
    Rob Cole's ExifMeta plugin displays the Subject Distance field (and much more).  Unfortunately, his Web site appears to be down again.  He used to be very active here, but he hasn't posted in several months.

  • How to set up my airport extreme to share my net connection. i have a ethernet cable from my isp which when i use in my mac, i have to enter username

    I access net through ethernet cable from my isp. so i just plug in the cable in my mac and in the browser it put the username & password. now i want to use my airport express to create a wireless network so i can access net from ipad and mac simultaneously. when i use airport express both my mac & ipad gets connected to airp exp but each of them ask for isp's username and password. i can only login from either one of them and access net in that one only. Pls advice???

    To allow your Mac to "see" the HDD attached to an AirPort Extreme Base Station (AEBS) that is configured as a bridge, just be sure to assign a static Private IP address to the AEBS. By default the AEBS is a DHCP client and will get a dynamic IP address from the upstream router that is acting as the DHCP server. Since this address can change over time, it would make it more difficult for network clients to find the HDD.

  • My iphone doesnt show up in my itunes. It shows up when i plug it into another laptop. Similarly, when i use someone else's iphone, that shows up in my itunes. Obviously my itunes wont recognise my iphone. Please help

    My iphone doesnt show up in my itunes. It shows up when i plug it into another laptop. Similarly, when i use someone else's iphone, that shows up in my itunes. Obviously my itunes wont recognise my iphone. Please help

    Hello ashbyy123,
    Thank you for using Apple Support Communities.
    For more information, take a look at:
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/ts1538
    2. Check the USB cable
    3. Verify that Apple Mobile Device Support is installed
    4. Restart the Apple Mobile Device Service
    5. Verify that the Apple Mobile Device USB Driver is installed
    6. Check for third-party software conflicts
    Have a nice day,
    Mario

  • When I use Merge duplicate Values

    Hi
    When I use MERGE for to INSERT It is duplicating values, I put condition in ON
    MERGE                         /*+  append nologging */ INTO sysadm.ps_loc_item_sn_zz2 t3
       USING (WITH tmp_ps_loc_item AS
                   (SELECT loc_cntr_id_sn, setid, companyid, effdt, setid_product, loc_product_sn,
                           ROW_NUMBER () OVER (PARTITION BY loc_cntr_id_sn, setid, companyid, effdt, setid_product, loc_product_sn ORDER BY linha)
                                                                                          seqno_item_sn,
                           loc_item_status, NULL ken_data_ativ_sn, NULL inactive_date_sn,
                           'LO' cntrct_origin_sn, SYSDATE row_added_dttm,
                           'CARGA PS 29052007' row_added_oprid, SYSDATE row_lastmant_dttm,
                           'CARGA PS 29052007' row_lastmant_oprid, 0 syncid, NULL syncdttm,
                           ken_component_sn
                      FROM (SELECT t1.*, ROWNUM linha
                              FROM sysadm.tmp_equip_crm t1,
                                   (SELECT     LEVEL l
                                          FROM DUAL
                                    CONNECT BY LEVEL <= 100)
                             WHERE l <= t1.qtd) )
              SELECT t2.loc_cntr_id_sn, t2.setid, companyid, effdt, setid_product, loc_product_sn,
                     t2.seqno_item_sn, loc_item_status, t5.ken_data_ativ_sn, inactive_date_sn,
                     cntrct_origin_sn, row_added_dttm, row_added_oprid, row_lastmant_dttm, syncid,
                     syncdttm, t2.ken_component_sn
                FROM tmp_ps_loc_item t2, sysadm.tmp_data_ativa t5
               WHERE t2.loc_cntr_id_sn = t5.loc_cntr_id_sn(+)
                 AND t2.ken_component_sn = t5.ken_component_sn(+)
                 AND t2.loc_item_status = t5.loc_item_status_sn(+)
                 AND t2.seqno_item_sn = t5.seqno_item_sn(+)) t4
       ON (    t3.loc_cntr_id_sn = t4.loc_cntr_id_sn
           AND t3.setid = t4.setid
           AND t3.companyid = t4.companyid
           AND t3.effdt = t4.effdt
           AND t3.setid_product = t4.setid_product
           AND t3.loc_product_sn = t4.loc_product_sn
           AND t3.seqno_item_sn = t4.seqno_item_sn)
       WHEN MATCHED THEN
          UPDATE
             SET t3.syncid = 0
       WHEN NOT MATCHED THEN
          INSERT (loc_cntr_id_sn, setid, companyid, effdt, setid_product, loc_product_sn, seqno_item_sn,
                  loc_item_status_sn, ken_data_ativ_sn, inactive_date_sn, cntrct_origin_sn,
                  row_added_dttm, row_added_oprid, row_lastmant_dttm, row_lastmant_oprid, syncid,
                  syncdttm)
          VALUES (t4.loc_cntr_id_sn, t4.setid, t4.companyid, t4.effdt, t4.setid_product,
                  t4.loc_product_sn, t4.seqno_item_sn, loc_item_status, t4.ken_data_ativ_sn,
                  t4.inactive_date_sn, t4.cntrct_origin_sn, t4.row_added_dttm, t4.row_added_oprid,
                  t4.row_lastmant_dttm, t4.ken_component_sn, t4.syncid, t4.syncdttm);

    I don't understand what you mean exactly?
    When an SQL statement encounters an error then all
    its work is rolled back ...
    So why do you expect that it worùs otherwise?simply
    WHEN MATCHED THEN      UPDATE         SET t3.syncid = 0Only

  • I have a MacBook Pro and just added an airport express to listen to my iTunes on my stereo. How do I get Firefox to use my AX when I use Grooveshark or Pandora?

    i have a MacBook Pro and just added an airport express to listen to my iTunes on my stereo. How do I get Firefox to use my AX when I use Grooveshark or Pandora?

    If the purchases are all from the same account then you can share the content by authorizing each device.
    If you have separate accounts then you have to be authorized to use the content purchased from another account.
    MJ

  • Not right data when row_number used in inner-view sql query...

    Hi ,
    I use the below sql statement which displays the right data
    select CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE , SUM_POSOTITA , row_number() over(partition by code_farmakou order by sum_posotita desc) from
      (SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES ,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_CLINIC A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_EX_IATR A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_FOREON_MS A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_GEN_SINT_KLIN A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_GEN_SINT_EX_IATR A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS)The data are:
    CODE_FARMAKOU                            EMP_NAME                                                                         PACKTYPE                     PACKSIZE                  SUM_POSOTITA ROW_NUMBER()OVER(PARTITIONBYCO
    0000002419                               FACTREL INJECTION                                                                VIAL                         2 ML                                 5                              1
    0000014071                               DOPAMINE HYDROCHLORIDE                                                           VIAL                         5 ML X 25                           30                              1
    0000086289                               DETUSSIN EXPECTORANT                                                             BOT                          120 ML                               3                              1
    1000000760                               DEPON                                                                            BT                           20(BLIST2X10)                        2                              1
    1000000760                               DEPON                                                                            BT                           20(BLIST2X10)                        1                              2
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                       45                              1
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                        1                              2
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                        1                              3
    1000014127                               DEPON VIT. C                                                                     BT                           2TUBX10                              6                              1
    1000014127                               DEPON VIT. C                                                                     BT                           2TUBX10                              2                              2
    1000016655                               KABIVEN                                                                          BT                           50ÖÕÓ.×1,7ML                        21                              1
    1000016655                               KABIVEN                                                                          BT                           50ÖÕÓ.×1,7ML                         2                              2However , when i use the below statement , in order not to display the row_number (so i use row_number function in inner-view) the data are different--in different order... why is that????
    select CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE , SUM_POSOTITA from
    select CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE , SUM_POSOTITA , row_number() over(partition by code_farmakou order by sum_posotita desc) from
      (SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES ,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_CLINIC A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_EX_IATR A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_AT_SINT_FOREON_MS A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_GEN_SINT_KLIN A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS
      UNION ALL
      SELECT CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, TO_DATE(DATES_EKTELESIS,'DD/MM/RRRR') DATES,SUM(POSOTITA) SUM_POSOTITA
              FROM  EKTELESI_GEN_SINT_EX_IATR A, MITROO_FARMAKOU B
               WHERE CODE_FARMAKOU = FARMAK_CODE
               GROUP BY CODE_FARMAKOU,EMP_NAME,PACKTYPE,PACKSIZE, DATES_EKTELESIS)
      )and its data are:
    CODE_FARMAKOU                            EMP_NAME                                                                         PACKTYPE                     PACKSIZE                  SUM_POSOTITA
    1000016655                               KABIVEN                                                                          BT                           50ΦΥΣ.Χ1,7ML                        21
    1000016655                               KABIVEN                                                                          BT                           50ΦΥΣ.Χ1,7ML                         2
    1000000760                               DEPON                                                                            BT                           20(BLIST2X10)                        2
    1000014127                               DEPON VIT. C                                                                     BT                           2TUBX10                              2
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                       45
    0000014071                               DOPAMINE HYDROCHLORIDE                                                           VIAL                         5 ML X 25                           30
    0000086289                               DETUSSIN EXPECTORANT                                                             BOT                          120 ML                               3
    1000014127                               DEPON VIT. C                                                                     BT                           2TUBX10                              6
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                        1
    1000003279                               MOXACEF                                                                          BT                           40(BLIST10X4)                        1
    0000002419                               FACTREL INJECTION                                                                VIAL                         2 ML                                 5
    1000000760                               DEPON                                                                            BT                           20(BLIST2X10)                        1NOTE :Sorry, I tried to pose some sample data using the "with" statement but i couldn't...the error ORA-32035 : unreferenced query name defined in WITH clause was displayed..
    Regards,
    Simon

    The optimizer has, well, optimized out the row_number because you never refer to its value in the outermost query.
    sql>select deptno, cnt, row_number() over (order by cnt desc) rn
      2    from (select deptno, count(*) cnt
      3            from emp
      4           group by deptno);
       DEPTNO       CNT        RN
           30         6         1
           20         5         2
           10         3         3
    3 rows selected.
    -- here because we include rn in the outermost query,
    -- the results are still ordered based on the analytical function result
    sql>select deptno, cnt, rn
      2    from (select deptno, cnt, row_number() over (order by cnt desc) rn
      3            from (select deptno, count(*) cnt
      4                    from emp
      5                   group by deptno));
       DEPTNO       CNT        RN
           30         6         1
           20         5         2
           10         3         3
    3 rows selected.
    -- but if we don't include rn in the outermost query,
    -- the optimizer leaves out the window sort and the results are in a different order
    sql>select deptno, cnt
      2    from (select deptno, cnt, row_number() over (order by cnt desc) rn
      3            from (select deptno, count(*) cnt
      4                    from emp
      5                   group by deptno));
       DEPTNO       CNT
           10         3
           20         5
           30         6
    3 rows selected.This just reinforces the point that if you want your results in a particular order, you need to provide an ORDER BY clause - don't rely on execution plans to do your sorting for you.

  • Photos loaded directly onto ipad air do not show up on PC anywhere when synced using itunes

    Photos loaded directly onto ipad air using Apple camera connection kit, do not show up on PC anywhere when synced using itunes

    They won't show in iTunes (iTunes is only used to copy photos to a device, not copy them off), but you should be able to copy them off either manually via My Computer (the iPad should show as a camera) or via windows camera wizard or windows live photo gallery depending upon your OS version.
    Copying photos : iOS: Import personal photos and videos from iOS devices to your computer

  • I am changing from Word to Pages. I have created my custom template with all my styles etc and that is what comes up when I go for a New Document. Fine. How do I get it to use the same Custom Template when I use Pages to open a Word document?

    I am changing from Word to Pages. I have created my custom template with all my styles etc and that is what comes up when I go for a New Document. Fine. How do I get it to use the same Custom Template when I use Pages to open a Word document?

    The template is a document in itself, it is not applied to an existing document whether it is a Pages document or a Word document converted to a Pages document.
    You would need to either copy and paste content, using existing styles, or apply the styles to the converted Word document.
    You can Import the Styles from an existing document and those imported Styles can be used to override the current document's styles:
    Menu > Format > Import Styles
    The process is simplified if the styles use the same names, otherwise you will need to delete the style you don't want and replace it with the one that you do want when asked, then the substitution is pretty straightforward.
    Peter

  • When I use the new Pages on my iPad, I can't open it on my new computer. It tells me that I must download the new Pages to see the Pages document, but when I try to download the new pages to my computer it tells me all apps are up to date.

    When I use the new Pages app. On my IPod  to type documents, I can't open them on my new computer. It sends me a message that I have to download a newer version of pages to see the Pages document. When I try to do that it tells me all my apps are up to date and will not allow me to upgrade the pages on my iMac.
    Any suggestions?

    What level of OS X is installed on your Mac (your profile is incomplete)?
    Barry

  • I have a Macbook Air with Mountain Lion..I upgraded to the latest version called Mavericks OX now it crashes a lot...when I use the shift key especially I now have version 10.9

    I have a Macbook Air with Mountain Lion..I upgraded to the latest version called mavericks ox now it crashes a lot...when I use the shift and Caps keys especially. I now have version 10.9. how can I get mountain lion back and get rid of this update?

    all of my software was current before i upgraded to maverick....i don't know why this is going on...any help?

Maybe you are looking for