博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

在客户模块分OU选择销售员的语句

Posted on 2012-09-03 17:38  奥客  阅读(395)  评论(0编辑  收藏  举报

begin
 fnd_client_info.set_org_context(82);
end;

select salesrep_id, name, salesrep_number, Org_Id
  from  (
SELECT JRS.SALESREP_ID,
       JRS.LAST_UPDATE_DATE,
       JRS.LAST_UPDATED_BY,
       JRS.CREATION_DATE,
       JRS.CREATED_BY,
       JRS.LAST_UPDATE_LOGIN,
       JRS.SALES_CREDIT_TYPE_ID,
       JRS.NAME,
       JRS.SALESREP_NUMBER,
       JRS.STATUS,
       JRS.START_DATE_ACTIVE,
       JRS.END_DATE_ACTIVE,
       JRS.GL_ID_REV,
       JRS.GL_ID_FREIGHT,
       JRS.GL_ID_REC,
       JRS.SET_OF_BOOKS_ID,
       JRS.ATTRIBUTE_CATEGORY,
       JRS.ATTRIBUTE1,
       JRS.ATTRIBUTE2,
       JRS.ATTRIBUTE3,
       JRS.ATTRIBUTE4,
       JRS.ATTRIBUTE5,
       JRS.ATTRIBUTE6,
       JRS.ATTRIBUTE7,
       JRS.ATTRIBUTE8,
       JRS.ATTRIBUTE9,
       JRS.ATTRIBUTE10,
       JRS.ATTRIBUTE11,
       JRS.ATTRIBUTE12,
       JRS.ATTRIBUTE13,
       JRS.ATTRIBUTE14,
       JRS.ATTRIBUTE15,
       JRS.ORG_ID,
       RES.SOURCE_EMAIL EMAIL_ADDRESS,
       RES.ASSIGNED_TO_GROUP_ID ASSIGNED_TO_USER_ID,
       RES.COST_CENTER,
       RES.CHARGE_TO_COST_CENTER,
       RES.COMPENSATION_CURRENCY_CODE,
       JRS.WH_UPDATE_DATE,
       JRS.PERSON_ID,
       RES.CATEGORY TYPE,
       JRS.SALES_TAX_GEOCODE,
       JRS.SALES_TAX_INSIDE_CITY_LIMITS,
       RES.COMMISSIONABLE_FLAG
  FROM JTF_RS_SALESREPS JRS, JTF_RS_RESOURCE_EXTNS_VL RES
 WHERE NVL(JRS.ORG_ID,
           NVL(TO_NUMBER(DECODE(SUBSTRB(USERENV('CLIENT_INFO'), 1, 1),
                                ' ',
                                NULL,
                                SUBSTRB(USERENV('CLIENT_INFO'), 1, 10))),
               -99)) =
       NVL(TO_NUMBER(DECODE(SUBSTRB(USERENV('CLIENT_INFO'), 1, 1),
                            ' ',
                            NULL,
                            SUBSTRB(USERENV('CLIENT_INFO'), 1, 10))),
           -99)
   AND JRS.RESOURCE_ID = RES.RESOURCE_ID
   AND RES.CATEGORY IN
       ('EMPLOYEE', 'OTHER', 'PARTY', 'PARTNER', 'SUPPLIER_CONTACT')
 
  )
 where nvl(status, 'A') = 'A'
   and salesrep_id != -1
   and salesrep_id != -2
   and (name like '蔡宇%' or name like '葛晓军%' )
  
 order by name