Query of multiple counts with conditions or multiple querys

I have this demo table
create table qtyrtu
rtunam varchar2(10) not null,
entity varchar2(10) not null,
linked number(3) not null
Insert into qtyrtu values ('02vh1', 'zdvh', 100);
Insert into qtyrtu values ('02vh2', 'zdvh', 0);
Insert into qtyrtu values ('02eh1', 'zdvh', 0);
Insert into qtyrtu values ('02sh1', 'stvh', 100);
Insert into qtyrtu values ('02sh1', 'stvh', 0);
Insert into qtyrtu values ('02sh1', 'stvh', 100);
Insert into qtyrtu values ('02tx', 'zdch', 100);
Insert into qtyrtu values ('02ta', 'zdch', 100);And my result expected would be the next one.
Entity | Count(rtunam linked by 100) | Count (rtunam linked by 0)
STVH    2   1
ZDCH    2   0   
ZDVH    1   2The problem is that I don't know how to query the 0, when I do my query(by column) it shows this:
select entity, count(rtunam) from qtyrtu where linked = 100 group by entity order by entity asc;
STVH    2
ZDCH    2   
ZDVH    1
select entity, count(rtunam) from qtyrtu where linked = 0group by entity order by entity asc;
STVH     1
ZDVH     2And I need to show all the counts( even the 0)
Regards

Hi,
Thanks for posting the sample data and the results; that really helps!
Here's one way:
SELECT    UPPER (entity)                    AS upper_entity
,       COUNT (CASE WHEN linked = 100 THEN 1 END)     AS cnt_100
,       COUNT (CASE WHEN linked = 0   THEN 1 END)     AS cnt_0
FROM       qtyrtu
GROUP BY  entity
;It looks like rtunam plays no role in this problem: is that right?
You already know how to get the separate column results, using a WHERE clause to ignore certain rows, but you can't use a WHERE clause here, because to want to ignore different rows for the two COUNT columns. A CASE expression can be like a WHERE clause that applies only to one column.

Similar Messages

  • UPDATE multiple columns with conditional SET parameters

    I have a procedure that updates multiple columns of a table using the procedure's parameter. Is it possible to have one update statement with conditional SET parameter?
    CREATE TABLE TEMP
    (POL_NUM NUMBER,
    OED DATE,
    TERM NUMBER,
    TRANS_CD CHAR(2));
    INSERT INTO TEMP VALUES (1, '1 AUG 2009', 12, 'NB');
    INSERT INTO TEMP VALUES (2, '4 AUG 2009', 12, 'XL');
    INSERT INTO TEMP VALUES (3, '2 AUG 2009', 12, 'RN');
    COMMIT;
    CREATE OR REPLACE PROCEDURE TMP_PROC (
      pPOL_NUM NUMBER,
      pOED IN DATE,
      pTERM IN NUMBER,
      pTRANS_CD CHAR2)
    AS
    BEGIN
      IF pOED IS NOT NULL THEN
        UPDATE TEMP SET OED = pOED WHERE POL_NUM = pPOL_NUM;
      END IF;
      IF pTERM IS NOT NULL THEN
        UPDATE TEMP SET TERM = pTERM WHERE POL_NUM = pPOL_NUM;
      END IF;
      IF pTRAN_CD IS NOT NULL THEN
        UPDATE TEMP SET TRANS_CD = pTRANS_CD WHERE POL_NUM = pPOL_NUM;
      END IF;
      COMMIT;
    EXCEPTION
      WHEN OTHERS THEN
         NULL;
    END;Is it possible to replace multiple IFs from the code to have only one UPDATE statement with condition that update the column only if the passed parameter is not null? In real scenario I have more than 3 columns and I don't want to write many IF blocks.
    Please help Gurus!!
    Edited by: Kuul13 on Sep 18, 2009 1:26 PM

    Hi,
    You certainly don't want to issue separate UPDATE statements for every column; that will be really inefficent.
    SQL has several ways to implement IF-THEN-ELSE logic. CASE is the most versatile, but NVL will do everything you need for this job. You can use one of those to set a column to itself (and therefore not really update that column) when appropriate.
    For example:
    CREATE OR REPLACE PROCEDURE TMP_PROC (
      pPOL_NUM   IN       NUMBER,
      pOED          IN   DATE,
      pTERM          IN   NUMBER,
      pTRANS_CD  IN       CHAR
    AS
    BEGIN
         UPDATE  temp
         SET     oed      = NVL (poed,       oed)
         ,     term      = NVL (pterm,       term)
         ,     trans_cd = NVL (ptrans_cd, trans_cd)
         WHERE     pol_num      = ppol_num;
      COMMIT;     -- Maybe
    END    tmp_proc;"EXCEPTION WHEN OTHERS THEN NULL" is almost always a bad idea. If there's an error, don't you want to know about it? Shouldn't you at least log a message in a warnings table or something?
    Think careflully about whether or not you want to COMMIT every time you call this procedure.
    Just as it's inefficient to issue a separate UPDATE statement for every column, it's also inefficient to issue a separate UPDATE statement for every row. If efficiency is important, it should be possible to UPDATE several rows in a single UPDATE statement, using NVL (or CASE, or COALESCE, or NULLIF, or NVL2, or ...).
    This was a very well-written question! Thanks for providing the CREATE TABLE and INSERT statements, and such a clear explanation.

  • Multiple idoc with condition in BPM

    please let me know whether i need to go for BPM or not BPM
    The actual scenario is
    I will be receiving n no. of idocs including both idoc type PEXR2001 and IDCREF01(control idoc).
    Then I need to collected all payment idoc PEXR2001 which will be having one control idoc
    IDCREF01.  This will be grouped by checking
    if IDCREF01-E1IDRH1-PAYRUNID equals to PEXR2001-E1IDRH1-PAYRUNID and
    IDCREF01-E1IDRH1-PAYRUNDT equals to PEXR2001-E1IDRH1-PAYRUNDT
    so for example I will be having 5 payment idoc and 1 control.  in this I need to sum the
    value of field MOABETR which is in payment idoc. after this i need to check
    if IDCREF01-E1IDRS1-SUM01 equals to PEXR2001-E1IDKU5-MOABETR.
    if this condition is satisfied then i will be sending the file to both email adapter and
    file adapter otherwise failed file will be sending only to email adaper.
    I request to give detailed step in BPM if possible.

    Hi Mughda,
    How would i validate using createif node function as i also need to validate fields of all the segments of the same Idoc. ?
    Thanks,
    Amit

  • To retrieve the Multiple Count of Records for Multiple types

    Hi Can some one help me in this:
    I have a talbe (MyTable) in which a column(Column 1) will have values as (Value1, Value2 , Value3, Value4 and Value5) for Multiple Records .
    I need to write a query which can give me the count of All the existing Records with the values(Value1, Value2 , Value3, Value4 and Value5) by a Single Query.The Resulting Table should have the Columns as :(Value1, Value2 , Value3, Value4 and Value5) with the Corresponding Counts in the Table.
    Thanks in Advance,
    vijay kumar k.
    Plz help me asap as it is very much linked with my Work..

    Hello
    Well, it always helps if you can post a create table statement, some test data, and the result you are expecting....it doesn't take long and you'll be much more likely to get a quick response from someone who has some time in between things that very much related to their work...
    create table dt_test_values(col1 varchar2(10))
    insert into dt_test_values values('value1')
    insert into dt_test_values values('value1')
    insert into dt_test_values values('value2')
    insert into dt_test_values values('value2')
    insert into dt_test_values values('value2')
    insert into dt_test_values values('value3')
    insert into dt_test_values values('value3')
    insert into dt_test_values values('value4')
    insert into dt_test_values values('value4')
    insert into dt_test_values values('value4')
    insert into dt_test_values values('value4')
    insert into dt_test_values values('value5')
    insert into dt_test_values values('value5')
    insert into dt_test_values values('value6')
    insert into dt_test_values values('value7')
    insert into dt_test_values values('value7')
    SQL> SELECT
      2     SUM(DECODE(col1,'value1', 1, 0)) value1,
      3     SUM(DECODE(col1,'value2', 1, 0)) value2,
      4     SUM(DECODE(col1,'value3', 1, 0)) value3,
      5     SUM(DECODE(col1,'value4', 1, 0)) value4,
      6     SUM(DECODE(col1,'value5', 1, 0)) value5,
      7     SUM(DECODE(col1,'value6', 1, 0)) value6,
      8     SUM(DECODE(col1,'value7', 1, 0)) value7,
      9     SUM(DECODE(col1,'value8', 1, 0)) value8
    10  FROM
    11     dt_test_values
    12  /
       VALUE1    VALUE2    VALUE3    VALUE4    VALUE5    VALUE6    VALUE7    VALUE8
            2         3         2         4         2         1         2         0HTH
    David

  • Count With Condition

    Hi to All,
    This is Satheesh Charles, Newly join to this Forum.
    I want to count number of female patient under some condition,
    If Month = JAN & patient_gender = F i have to count all the F value.
    How to perform this operation ?. pls suggest.

    Hi Satheesh,
    Try this formula:
    numbervar count:=0;
    if = 'Jan' and ='F' then count++
    count;
    Drag this formula to the section where you want to display the count in the report.
    Hope this helps you!
    Regards,
    Anindita
    Edited by: Anindita Palit on Mar 26, 2009 2:14 PM

  • Count with multiple conditions (XML publisher)

    I'm trying to only count an EMPLID if multiple conditions have been met in an RTF.
    This works for 1 condition: <?count(xdoxslt:distinct_values(EMPLID[../FIRSTYEARFRESHMAN=1]))?>
    But how do I do multiple conditions? I've tried <?count(xdoxslt:distinct_values(EMPLID[../FIRSTYEARFRESHMAN=1] AND [../APPLIED_FOR_NEED_B=1]))?> and <?count(xdoxslt:distinct_values(EMPLID[../FIRSTYEARFRESHMAN=1 AND ../APPLIED_FOR_NEED_B=1]))?> but those both don't work.
    Thanks!

    similar problem for xdoxslt:distinct_values(EMPLID[condition1 and/or condition2])
    How to calculate count distinct (by xdoxslt:distinct_values) with a condition expression

  • Count number rows in multiple tables from one query

    Hi
    I was wondering if its possible to have a single query return the number of lines in multiple tables, for example i have the tables
    foo1
    pk_foo1
    and
    foo2
    pk_foo2
    They are not joined together by any contraints. So the pseudo code for the query would be something like
    SELECT numrows(pk_foo1), numrows(pk_foo2) FROM foo1, foo2
    Thanks!

    without a join you get a cartesian product for the query:
    SQL> select count(d.deptno),count(e.deptno)
      2  from dept d,emp e
      3  /
    COUNT(D.DEPTNO) COUNT(E.DEPTNO)
                105             105so you need to do a bit of trickery
      1  select a.cnt,b.cnt
      2  from
      3  ( select count(d.deptno) cnt from dept d ) a,
      4* ( select count(e.deptno) cnt from emp e) b
    SQL> /
           CNT        CNT
             7         15
    SQL> select count(*) from dept;
      COUNT(*)
             7
    SQL> select count(*) from emp;
      COUNT(*)
            15

  • Single report with multiple queries OR multiple reports with single query

    Hello Experts,
    I have a confusion regarding Live Office connection for many days. I asked many people but did not get a concrete answer. I am re-posting this question here and expecting an answer this time.
    The product versions that I am using are as follows:
    FrontEnd:
      BOE XI 3.1 SP4 FP 4.1
      Xcelsius Enterprise 2008 SP4
    Backend:
      SAP BW 7.0 EHP1
    I have created a dashboard which is getting data from a webi report using LO connections.
    The webi report has five report parts which are populated by five different queries.
    Now my question is, when the five LO connections are refreshed, is the webi report refreshed five times or just once?
    If the report is refreshed five times, then I guess it is better to have five different webi reports containing single report part, because in that way we can prevent same query being executed multiple times.
    SO what is the best practice- to have a single report having multiple queries - OR - to create multiple webi reports with single query?
    Thanks and Regards,
    PASG

    HI
    I think Best Practice is Multiple reports with single query
    Any way If LO connections refresh 5 time the query will refresh 5 timesRegards
    Venkat

  • Query to display multiple counts in the result

    Hi,
    I need to be able to display multiple counts for different items in the single result set:
    Here is the simplified schema:
    I have 2 tables:
    STATEMENT table:
    ===============
    statement_pk number,
    department varchar2(20)
    STATEMENT_INFO table:
    ===================
    statement_info_pk number,
    statement_fk number
    is_statement_done varchar2(1)
    is_statement_locked varchar2(1)
    I need to display counts of how many records where done and how records where locked in the
    single output:
    Statement_PK Department NumberOfStatementsDone# NumberofStatementsLocked#
    1          ABC_dept          3                    5
    2          DEF_dept          4                    8
    3          XYZ_dept          7                    2
    The following does not work:
    SELECT
    s.statement_pk,
    s.department,
    COUNT(r.statement_info_pk ) NumberOfStatementsDone# ,
    COUNT(rr.statement_info_pk ) NumberOfStatementsLocked#
    FROM STATEMENT s ,
    STATEMENT_INFO r,
    STATEMENT_INFO rr
    WHERE
         s.statement_pk = r.statement_fk
         AND     s.statement_pk = rr.statement_fk
         AND      is_statement_done = 'Y'      AND rr.is_statement_locked = 'Y'
    GROUP BY statement_pk, s.department
    I was trying to work with analytic function but could not figured it out either.
    Please help
    Thanks,
    Ia.

    this would be something like:
    SQL> r
      1  select statement_pk,
      2         department,
      3         sum(decode(is_statement_done, 'Y', 1, 0)) statement_done,
      4         sum(decode(is_statement_locked, 'Y', 1, 0)) statement_locked
      5  from   statement_info,
      6         statement
      7  where  statement_fk = statement_pk
      8* group by statement_pk, department
    STATEMENT_PK DEPARTMENT           STATEMENT_DONE STATEMENT_LOCKED
               1 ABC_dept                          4                1
               2 DEF_dept                          6                2
               3 XYZ_dept                          1                2
    SQL> Message was edited by:
    Leo Mannhart
    Craig you were faster

  • Problem with multiple counter plan containing running hrs and no of months

    Hey gurus,
    In my project the preventive maintenance of compressor is such that it is performed after 500 hrs or 6 months whichever comes first. Now i ve created a cycle set cosisting of 500 hrs and 6 months. In the multiple counter plan i ve assigned a counter to the plan for calculating 500 hrs and chosen the link as OR. I scheduled the plan and given the start date as 01.05.09. Now I am facing the following problem:
    Suppose my counter value reaches the 500 mark on 01.08.09. Now a maintenance order is generated. My client now wants that the next order should be generated after the counter reading reaches 1000 or the date reaches 01.02.10, ie, the order should be generated for next 500hrs or NEXT 6 MONTHS from
    the date of completion of first cycle, whichever comes first.
    Pls help....
    Regards,
    Abhishek

    Hi
    If u have scheduled ur plan according to cycle set. It will take the Point of contact as 6 months.
    OK
    Ex : Cycle set : 500 hrs and 6 months, maintained OR functions
    i have entered the measurement reading as 500.. thats why, it gives the call for todays date...
    see the next date will be after 6 months... If u update the measuring point only, it will open a order... otherwise.. once u have scheduled it for 6 months.. once in 6 months it will give a order...
    1     11.05.2009               0     New start  Save to call
    2     07.11.2009     07.11.2009          0     Scheduled  Hold
    3     06.05.2010     06.05.2010          0     Scheduled  Hold
    4     02.11.2010     02.11.2010          0     Scheduled  Hold
    5     01.05.2011     01.05.2011          0     Scheduled  Hold
    6     28.10.2011     28.10.2011          0     Scheduled  Hold
    7     25.04.2012     25.04.2012          0     Scheduled  Hold
    Schedule for a long period.. u will be able to understand the scenario...
    - Pithan

  • There are multiple users with the same display name

    Hi,
    We have a user and when she get an item assigned to her she sees the following alert:
    "There are multiple users with the same display name USERNAME and at least one of them does not have read permissions to some of the files"
    Now I looked in the database and when I run the following query with the username:
     SELECT     
         [ProviderDisplayName]  
        ,[DisplayName]  
        ,[HasDisplayName]  
        ,[Domain]  
        ,[AccountName]  
        ,[UniqueUserId]  
        ,[LastSync]  
      FROM [Tfs_Configuration].[dbo].[tbl_Identity] where displayname like '%USERNAME%'  
    Then I get 2 same usernames back, How can I get rid of one of them ? When I access TFS trough the portal I only find 1 occurence of this user.
    We use VS2013 and TFS2013 update 4
    Best regards

    Hi DSW,  
    Thanks for your post.
    In your query result, please check if these two users have the same Account Name. if they are two different Account Name in result, it indicate there’s two users have the same display name in your AD, please check that two users’ information in
    your AD. We suggest change one user’s display name in AD.  
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Multiple queries with 1 connection

    Can I execute multiple queries with one connection?
    //Example -
    <%
    String firstconn;
    Class.forName("org.gjt.mm.mysql.Driver");
    // create connection string
    firstconn = "jdbc:mysql://localhost/profile?user=mark&password=mstringham";
    // pass database parameters to JDBC driver
    Connection aConn = DriverManager.getConnection(firstconn);
    // query statement
    Statement firstSQLStatement = aConn.createStatement();
    String firstquery = "UPDATE auth_users SET last_log='" + rightnow + "'WHERE name='" + username + "' ";
    // get result code
    int firstSQLStatus = firstSQLStatement.executeUpdate(firstquery);
    // close connection
    firstSQLStatement.close();
    %>     
    Now, instead of building a new connection for each query, can I use the same connection info for another query?
    if so - how do you do this?
    thanks for any help.
    Mark

    Create multiple statement objects from your connection. It's a good idea to close these in a finally block after you're done with them
    Connection conn = null;
    Statement stmt1 = null;
    Statement stmt2 = null;
    try {
        conn = DriverManager.getConnection();
        stmt1 = conn.createStatement();
        // some sql here
        stmt2 = conn.createStatement();
        // some more sql here
    } finally {
        if ( stmt1 != null ) stmt1.close();
        if ( stmt2 != null ) stmt2.close();

  • Having multiple problems with script - NTFS Permissions and AD Groups

    Hi, all!  I'm having multiple problems with my first script I've written with Powershell.  The script below does the following:
    1. Prompts the user for a corporate division under which a shared folder will be created, and adjusts variables accordingly.
    2. Prompts if the folder will be a global folder or an office/location-specific folder, and makes appropriate adjustments to variables.
    3.  If a global folder, prompts for the name.  If an office/location-specific folder, prompts for each component of the street address, city and state and an optional modifier.  I've prompted for this information in this way because the information
    is used differently later on in the script.
    4.  Verifies the entered information and requests confirmation to proceed.
    5.  Creates the folder.
    6.  Creates an AD OU and/or security group(s).
    7.  Applies appropriate security groups to the new folder and removes undesired permissions.
    Import-Module ActiveDirectory
    $Division = ""
    $DivAbbr = ""
    $OU = ""
    $OUDrive = "AD:\"
    $FolderName = ""
    $OUName = ""
    $GroupName = ""
    $OURoot = "ou=DFS Restructure Testing OU,ou=Pennsylvania Camp Hill 4410 Industrial Park Rd,ou=Locations,ou=Camp Hill,dc=jacobsonco,DC=com"
    $FSRoot = "E:\"
    $FolderPath = ""
    $DefaultFolders = "Archive","Customer Service","Equipment","Inbounds","Management","Outbounds","Processes","Projects","Quality","Reports","Returns","Safety","Schedules","Time Keeping","Training"
    [bool]$Location = 0
    do {
    $userInput = Read-Host "Enter CLS Division: (W)arehousing, (S)taffing, or (P)ackaging"
    Switch ($userInput)
    W {$Division = "Warehousing"; $DivAbbr = "WHSE"; $OU = "ou=Warehousing,"; break}
    S {"Staffing is not yet implemented."; break}
    P {"Packaging is not yet implemented."; break}
    default {"Invalid choice. Please re-enter."; break}
    while ($DivAbbr -eq "")
    write-host ""
    write-host ($Division + " was selected.")
    $FolderPath = $Division + "\"
    write-host ""
    $choice = ""
    do {
    $choice = Read-Host "Will this be a (G)lobal folder or (L)ocation folder?"
    Switch ($choice)
    G {$Location = $false; break}
    L {$Location = $true; $FolderPath = $FolderPath + "Locations\"; $OU = "ou=Locations," + $OU; break}
    default {"Invalid choice. Please re-enter."; $choice = ""; break}
    while ($choice -eq "")
    write-host ""
    write-host ("Location is set to: " + $Location)
    write-host ""
    if ($Location -eq $false) {
    $FolderName = Read-Host "Please enter folder name:"
    $GroupName = $DivAbbr + " " + $FolderName
    } else {
    $input = Read-Host "Please enter two-letter state abbreviation:"
    $FolderName = $FolderName + $input + " "
    $input = Read-Host "Please enter city:"
    $FolderName = $FolderName + $input + " "
    $input = Read-Host "Please enter street address number only:"
    $FolderName = $FolderName + $input
    $GroupName = $DivAbbr + " " + $FolderName
    $FolderName = $FolderName + " "
    $input = Read-Host "Please enter street name:"
    $FolderName = $FolderName + $input
    $input = Read-Host "Please enter any optional information to appear in folder name:"
    if ($input -ne "") {
    $FolderName = $FolderName + " " + $input
    $OUName = $FolderName
    write-host
    write-host "Path for folder: "$FSRoot$FolderPath$FolderName
    write-host "AD Path: "$OUDrive$OU$OURoot
    write-host "New OU Name: "$OUName
    write-host -NoNewLine "New Security Group names: "$GroupName
    if ($Location -eq $true) { write-host " and "$GroupName" MGMT" }
    write-host
    $input = Read-Host "Please confirm creation of new site/folder: (Y/N) "
    if ($input -ne "Y") { Exit }
    write-host
    write-host -NoNewLine "Folder exists: "; Test-Path ($FSRoot + $FolderPath + $FolderName)
    if (Test-Path ($FSRoot + $FolderPath + $FolderName)) {
    Write-Host "Folder already exists! Skipping folder creation..."
    } else {
    write-host "Folder does not exist. Creating..."
    new-item -path ($FSRoot + $FolderPath) -name $FolderName -itemtype directory
    Set-Location ($FSRoot + $FolderPath + $FolderName)
    if ($Location -eq $true) {
    $tempOUName = "ou=" + $OUName + ","
    write-host
    write-host $OUDrive$tempOUName$OU$OURoot
    write-host
    write-host -NoNewLine "OU exists: "; Test-Path ($OUDrive + $tempOUName + $OU + $OURoot)
    if (Test-Path ($OUDrive + $tempOUName + $OU + $OURoot)) {
    Write-Host "OU already exists! Skipping OU creation..."
    } else {
    write-host "OU does not exist. Creating..."
    New-ADOrganizationalUnit -Name $OUName -Path ($OU + $OURoot) -ProtectedFromAccidentalDeletion $false
    $GroupNameMGMT = $GroupName + " MGMT"
    if (!(Test-Path ($OUDrive + "CN=" + $GroupName + "," + $tempOUName + $OU + $OURoot))) { write-host "Normal user group does not exist. Creating..."; New-ADGroup -Name $GroupName -GroupCategory Security -GroupScope Global -Path ("OU=" + $OUName + "," + $OU + $OURoot)}
    if (!(Test-Path ($OUDrive + "CN=" + $GroupNameMGMT + "," + $tempOUName + $OU + $OURoot))) { write-host "Management user group does not exist. Creating..."; New-ADGroup -Name $GroupNameMGMT -GroupCategory Security -GroupScope Global -Path ("OU=" + $OUName + "," + $OU + $OURoot)}
    $FolderACL = get-acl ($FSRoot + $FolderPath + $FolderName)
    $FolderACL.SetAccessRuleProtection($True,$True)
    # $FolderACL.Access | where {$_.IdentityReference -eq "BUILTIN\Users"} | %{$FolderACL.RemoveAccessRuleAll($_)}
    $BIUsers = New-Object System.Security.Principal.NTAccount("BUILTIN\Users")
    $BIUsersSID = $BIUsers.Translate([System.Security.Principal.SecurityIdentifier])
    write-host $BIUsersSID.Value
    # out-string -inputObject $BIUsers
    $Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($BIUsersSID.Value,"ReadAndExecute,AppendData,CreateFiles,Synchronize","ContainerInherit, ObjectInherit", "None", "Allow")
    $FolderACL.RemoveAccessRuleAll($Ar)
    Set-ACL ($FSRoot + $FolderPath + $FolderName) $FolderACL
    get-acl ($FSRoot + $FolderPath + $FolderName) | fl
    $FolderACL = get-acl ($FSRoot + $FolderPath + $FolderName)
    $ADGroupName = "JACOBSON\" + $GroupName
    $objUser = New-Object System.Security.Principal.NTAccount($ADGroupName)
    $objUser.Translate([System.Security.Principal.SecurityIdentifier]).Value
    write-host $ADGroupName
    write-host $objUser.Value
    $Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($ADGroupName,"ReadAndExecute","ContainerInherit, ObjectInherit", "None", "Allow")
    Out-String -InputObject $ar
    $FolderACL.AddAccessRule($Ar)
    $ADGroupName = "JACOBSON\" + $GroupNameMGMT
    $Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($ADGroupName, "Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
    Out-String -InputObject $ar
    $FolderACL.AddAccessRule($Ar)
    Set-ACL ($FSRoot + $FolderPath + $FolderName) $FolderACL
    } else {
    $tempOUName = "cn=" + $GroupName + ","
    write-host
    write-host $OUDrive$tempOUName$OU$OURoot
    write-host
    write-host -NoNewLine "Group exists: "; Test-Path ($OUDrive + $tempOUName + $OU + $OURoot)
    if (Test-Path ($OUDrive + $tempOUName + $OU + $OURoot)) {
    Write-Host "Security group already exists! Skipping new security group creation..."
    } else {
    write-host "Security group does not exist. Creating..."
    New-ADGroup -Name $GroupName -GroupCategory Security -GroupScope Global -Path ($OU + $OURoot)
    $FolderACL = get-acl ($FSRoot + $FolderPath + $FolderName)
    $ADGroupName = "JACOBSON\" + $GroupName
    $FolderACL.SetAccessRuleProtection($True,$True)
    $Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($ADGroupName,"Modify","ContainerInherit, ObjectInherit", "None", "Allow")
    $FolderACL.AddAccessRule($Ar)
    $FolderACL.Access | where {$_.IdentityReference -eq "BUILTIN\Users"} | %{$FolderACL.RemoveAccessRuleAll($_)}
    Set-ACL ($FSRoot + $FolderPath + $FolderName) $FolderACL
    My problems right now are in the assignment/removal of security groups on the newly-created folder, and the problems are two-fold.  Yes, I am running this script as an Administrator.
    First, I am unable to remove the BUILTIN\Users group from the folder when this is an office/location-specific folder.  I've tried to remove the group in several different ways, and none are having any effect.  Oddly, if I type in the lines directly
    into Powershell, they work as expected.  I've tried the following methods:
    $FolderACL = get-acl ($FSRoot + $FolderPath + $FolderName)
    $FolderACL.SetAccessRuleProtection($True,$True)
    $FolderACL.Access | where {$_.IdentityReference -eq "BUILTIN\Users"} | %{$FolderACL.RemoveAccessRuleAll($_)}
    Set-ACL ($FSRoot + $FolderPath + $FolderName) $FolderACL
    $FolderACL = get-acl ($FSRoot + $FolderPath + $FolderName)
    $FolderACL.SetAccessRuleProtection($True,$True)
    $BIUsers = New-Object System.Security.Principal.NTAccount("BUILTIN\Users")
    $BIUsersSID = $BIUsers.Translate([System.Security.Principal.SecurityIdentifier])
    $Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($BIUsersSID.Value,"ReadAndExecute,AppendData,CreateFiles,Synchronize","ContainerInherit, ObjectInherit", "None", "Allow")
    $FolderACL.RemoveAccessRuleAll($Ar)
    Set-ACL ($FSRoot + $FolderPath + $FolderName) $FolderACL
    In the first case, the script goes through and has no apparent effect because afterwards, I do a get-acl and the BUILTIN\Users group is still there, although when looking through the GUI, inheritance appears to have been broken from the parent folder.
    In the second case, I get the following error message:
    Exception calling "RemoveAccessRuleAll" with "1" argument(s): "Some or all identity references could not be translated."
    At C:\Users\tesdallb\Documents\FileServerBuild.ps1:110 char:5
    +     $FolderACL.RemoveAccessRuleAll($Ar)
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : IdentityNotMappedException
    This seems strange that the local server is unable to translate the SID of a BUILTIN account.  I've also tried explicitly putting in the BUILTIN\Users SID in place of the variable in the New-Object line, but that gives me the same error.  I've
    also tried the solutions given in this thread:
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/ad59dc58-1360-4652-ae09-2cd4273cbd4f/remove-acl-issue?forum=winserverpowershell and at this URL:
    http://technet.microsoft.com/en-us/library/ff730951.aspx but these solutions also failed to have any effect.
    My second problem is when I try to apply the newly-created security groups, I also will get the "Some or all identity references could not be translated."  I thought I had found a workaround to the problem by adding the -PassThru option to
    the New-ADGroup commands, because it would output the SID of the group after creation, however a few lines later, the server is unable to translate the account to apply the security groups to the folder.
    My first Powershell script has been working well up to this point and now I seem to have hit a showstopper.  Any help is appreciated.
    Thanks!

    I was hoping to stay with strictly Powershell, but unless I can find a Powershell solution, I may resort to ICACLS.
    As for the problems with my groups not being translatable right after creating them, I think I have solved this problem by using the -Server parameter on all my New-ADGroup commands and this example code seems to have gotten around the translation problem,
    again utilizing the -Server parameter on the Get-ADGroup command:
    get-acl ($FSRoot + $FolderPath + $FolderName) | fl
    $FolderACL = get-acl ($FSRoot + $FolderPath + $FolderName)
    # Add the new normal users group to the folder with Read and Execute permissions
    $GroupSID = Get-ADGroup -Identity $GroupName -Server chadc01.jacobsonco.com | Select-Object -ExpandProperty SID
    $SIDIdentity = New-Object System.Security.Principal.SecurityIdentifier($GroupSID)
    $Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($SIDIdentity,"ReadAndExecute","ContainerInherit, ObjectInherit", "None", "Allow")
    $FolderACL.AddAccessRule($Ar)
    # Add the management users group to the folder with Modify permissions
    $GroupMGMTSID = Get-ADGroup -Identity $GroupNameMGMT -Server chadc01.jacobsonco.com | Select-Object -ExpandProperty SID
    $SIDIdentity = New-Object System.Security.Principal.SecurityIdentifier($GroupMGMTSID)
    $Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($SIDIdentity, "Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
    $FolderACL.AddAccessRule($Ar)
    Set-ACL ($FSRoot + $FolderPath + $FolderName) $FolderACL
    Going this route seems to ensure that the Domain Controller I'm creating my groups on is the same one that I'm querying for the group's SID to use in the FileSystemAccessRule.  It's been working fairly consistently.
    Still having issues with the translation of the BUILTIN\Users group, though. 

  • In  a SQL query whihc has join, How to reduce Multiple instance of a table

    in a SQL query which has join, How to reduce Multiple instance of a table
    Here is an example: I am using Oracle 9i
    is there a way to reduce no.of Person instances from the following query? or can I optimize this query further?
    TABLES:
    mail_table
    mail_id, from_person_id, to_person_id, cc_person_id, subject, body
    person_table
    person_id, name, email
    QUERY:
    SELECT p_from.name from, p_to.name to, p_cc.name cc, subject
    FROM mail, person p_from, person p_to, person p_cc
    WHERE from_person_id = p_from.person_id
    AND to_person_id = p_to.person_id
    AND cc_person_id = p_cc.person_id
    Thnanks in advance,
    Babu.

    SQL> select * from mail;
            ID          F          T         CC
             1          1          2          3
    SQL> select * from person;
           PID NAME
             1 a
             2 b
             3 c
    --Query with only ne Instance of PERSON Table
    SQL> select m.id,max(decode(m.f,p.pid,p.name)) frm_name,
      2         max(decode(m.t,p.pid,p.name)) to_name,
      3         max(decode(m.cc,p.pid,p.name)) cc_name
      4  from mail m,person p
      5  where m.f = p.pid
      6  or m.t = p.pid
      7  or m.cc = p.pid
      8  group by m.id;
            ID FRM_NAME   TO_NAME    CC_NAME
             1 a          b          c
    --Expalin plan for "One instance" Query
    SQL> explain plan for
      2  select m.id,max(decode(m.f,p.pid,p.name)) frm_name,
      3         max(decode(m.t,p.pid,p.name)) to_name,
      4         max(decode(m.cc,p.pid,p.name)) cc_name
      5  from mail m,person p
      6  where m.f = p.pid
      7  or m.t = p.pid
      8  or m.cc = p.pid
      9  group by m.id;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 902563036
    | Id  | Operation           | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |        |     3 |   216 |     7  (15)| 00:00:01 |
    |   1 |  HASH GROUP BY      |        |     3 |   216 |     7  (15)| 00:00:01 |
    |   2 |   NESTED LOOPS      |        |     3 |   216 |     6   (0)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| MAIL   |     1 |    52 |     3   (0)| 00:00:01 |
    |*  4 |    TABLE ACCESS FULL| PERSON |     3 |    60 |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       4 - filter("M"."F"="P"."PID" OR "M"."T"="P"."PID" OR
                  "M"."CC"="P"."PID")
    Note
       - dynamic sampling used for this statement
    --Explain plan for "Normal" query
    SQL> explain plan for
      2  select m.id,pf.name fname,pt.name tname,pcc.name ccname
      3  from mail m,person pf,person pt,person pcc
      4  where m.f = pf.pid
      5  and m.t = pt.pid
      6  and m.cc = pcc.pid;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 4145845855
    | Id  | Operation            | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |        |     1 |   112 |    14  (15)| 00:00:01 |
    |*  1 |  HASH JOIN           |        |     1 |   112 |    14  (15)| 00:00:01 |
    |*  2 |   HASH JOIN          |        |     1 |    92 |    10  (10)| 00:00:01 |
    |*  3 |    HASH JOIN         |        |     1 |    72 |     7  (15)| 00:00:01 |
    |   4 |     TABLE ACCESS FULL| MAIL   |     1 |    52 |     3   (0)| 00:00:01 |
    |   5 |     TABLE ACCESS FULL| PERSON |     3 |    60 |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |   6 |    TABLE ACCESS FULL | PERSON |     3 |    60 |     3   (0)| 00:00:01 |
    |   7 |   TABLE ACCESS FULL  | PERSON |     3 |    60 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("M"."CC"="PCC"."PID")
       2 - access("M"."T"="PT"."PID")
       3 - access("M"."F"="PF"."PID")
    PLAN_TABLE_OUTPUT
    Note
       - dynamic sampling used for this statement
    25 rows selected.
    Message was edited by:
            jeneesh
    No indexes created...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Multiple Problems with PDF InDesign, Bridge, and Acrobat Reader

    I create proof books with a blend of Adobe Bridge & InDesign.
    Here is my work flow: I will BOLD the errors I am having and need help with.
    Step 1.) I create contact sheets in Bridge and save them as PDF's
    Problem with Bridge ( I have another posting for this thread as well under Bridge) I cannot save PDF's larger than 400ish photos at 300ppi (important for my printer) without it saving as a blank PDF. COMPLETELY EMTPY! So I have to split up my photos into groups of 400 or less photos then patch them back together.
    Problem with Acrobat: If I patch those PDF’s back together with Adobe Acrobat (a suggestion from another person on here) they save great but I get an error when I try to import them in indesign. The error reading: ERROR. Cannot determine page count.
    Please open the PDF file in Acrobat, do a “Save As…” and try again. (99)
    Step 2.) I use a script (MultiPageImporter2.2.1.jsx) to import the PDF's into Indesign. (if saved as one pdf in acrobat I get the above error)
    Problem With InDesign: I run this importer script in InDesign to create my books with a template I use from my printers. Well since I have to import multiple pdf with multiple pages ( because I can’t piece them together without the above error. Then I have this problem:
    I place a pdf with 1-226 pages in. I start this on page 1.
    I place the next pdf with 1-141 pages in. I start this on page 227.
    An error pops up that says I MUST start my import on page 226!!!!!!!!!! I don’t want to import on page 226 because I have two photos on that page!
    I tried it several ways and no matter what I loose my last page of my first import.
    PLEASE someone help me! I feel like I might be doing something really silly but I’ve spent 7.5 hours today working on this books with error after error.
    I have done all the updates on my computers and nothing works. I use two macs and both have the same errors. I have a mac-book Pro | snow leopard and a Imac | snow leopard.
    Thanks much!

    All your problems seem to stem from the PDFs that you are making from Bridge.  What you are describing should be perfectly possible, but the fact that Bridge doesn't want to make a PDF with more than 400 photos and it all goes downhill from there makes me suspect Bridge.
    Here's a plugin that may help?  Looks pretty cheap for what it does.
    Apart from that I'd try to clean up the PDFs that Bridge is producing if Indesign doesn't like them.  One way would be to print to a new PDF, after you've combined them as necessary.
    As to the last pronlem you mention, where it forces you to place on page 226, have you tried creating a blank page 227 first, before you try placing?

Maybe you are looking for

  • Query a List of Open WMI connections on a server from a remote system

    We are monitoring a specific windows service on a server using Sitescope remote monitoring. The sitescope system uses a WMI method to Check if the service on a specific server is up or not. Initially it works like a charm but over time the WMI connec

  • Mac mini 2012 - Video Problem (Not HDMI Flickering)

    Hello guys, I have a problem with video, it causes to shut down the monitor while is playing Chefville in facebook, i had no idea why would to turn off monitor. It doesn't present any "beep" sound, it seems Intel HD4000 is a defective. I waited like

  • Java.lang.ClassCastException in glassfish

    I'm working on a simple application with Glassfish and OSGI. I found this tutorial: http://blogs.oracle.com/arungupta/entry/totd_154_dynamic_osgi_services I modified the example. You can find my customized example file: http://uploading.com/files/cf1

  • Non Clustered Indexing not working for SQL server 2005

    I have create two non clustered index on two particular tables. Now the problem is its working fine..but after restarting my server its working stop and then again I have to delete that index and recreate it.

  • Tolerance in condition

    Hi guys, i need to calculate tolerance of equal to or greater than the user input of a certain KF how do i do that using a formula variable in a condition of type customer exit, i mean i know how to code for a characteristic variable but to change th