Clarity

 View Only
  • 1.  HELP - Need help with "joins" in my Query

    Posted Oct 03, 2012 11:54 AM
    Hello,

    I'm attempting to get output from the database, relating to Documents in Clarity, and I'm having issues with the Joins of some "last minute" information that I need to include. I know where the information/data resides but I can't get the "joins" correct.

    I need to include the following:
    1. User Names and User Ids: The Users Ids I need to disply are in the CLB_DMS_VERSIONS table in the CREATED_BY column. The CREATED_BY column is a numeric value and I do not see any data for Names in this Table (Or any of the Document tables, CLB_DMS_**). The only place that I know of that contains data for User Names is in the CMN_SEC_USERS Table under the column "USER_NAME."
    2. Version "Date, Time" stamp: Table=CLB_DMS_FILES, Column=“Created_Date.
    3. Version "Checked-In By": Table=CLB_DMS_FILES, Column=Created_By
    4. Version "Comments":
    Table=CLBS_DMS_VERSIONS, Column=“CHECK_IN_COMMENT”
    5. Collaboration Path: I need to pull in the collaboration path for the Project: example: /Root/DMS/PM/Projects/123456/123 Meeting Notes. I'm not sure were this path is. I'm only able to locate the "root
    PATH under Table=CLB_DMS_FOLDERS, Column="PATH". (I have this PATH in my query below but it's not what I need). I need the full Path to the Document name - "123 Meeting Notes."


    Can someone help me with getting the "joins" in my existing query below? (This query works on it's own - - again I need to add the additional information).

    I need to add it into this query that I started:
    SELECT
    INV.NAME INV_PROJECT_NAME,
    INV.CODE PROJECT_ID,
    VER.VERSION_NUMBER VERSION,
    VER.LAST_UPDATED_DATE LAST_UPDA,
    VER.BYTE_SIZE BYTE_SIZE,
    VER.IS_LATEST VER_IS_LATEST,
    FLD.PATH_NAME PATH,
    FIL.NAME FILE_NAME

    FROM CLB_DMS_VERSIONS VER
    left JOIN CLB_DMS_FILES FIL ON VER.FILE_ID = FIL.ID
    left JOIN CLB_DMS_FOLDERS FLD ON FIL.PARENT_FOLDER_ID = FLD.ID
    left JOIN INV_INVESTMENTS INV ON FLD.ASSOC_OBJ_ID = INV.ID

    where trunc(ver.last_updated_date) < '2011-10-01'
    and ver.is_latest=0



    Thanks much!


  • 2.  RE: HELP - Need help with "joins" in my Query

    Posted Oct 03, 2012 12:06 PM
    For user names you can do a sub query to join to CMN_SEC_USERS.

    Below is a portion of a query we use for a document portlet, which should get you started - this has the code for the folder path, and examples of a sub-query (look at author)..
    select 
    
    f.id file_id,
    srm.id project_id,
    srm.unique_name project_code,
    srm.name project_name,
    f.name file_name,
    ver.byte_size,
    ver.version_number version,
    ver.last_updated_date,
    (case ver.is_latest when '1' then (case f.lock_owner_id when 0 then null else f.last_updated_date end ) else null end) checked_out_date,
    (case ver.is_latest when '1' then (case f.lock_owner_id when 0 then ver.version_created_date else null end ) else ver.version_created_date end) checked_in_date,
    
    (select full_name from srm_resources where user_id=f.lock_owner_id) locked_by,
    (case ver.is_latest when '1' then (case f.lock_owner_id when 0 then 'In' else 'Out' end ) else 'In' end) Checked_in_out,
    
    (select full_name from srm_resources where user_id=f.owner_id) author,
    substring(fol.path_name+'/'+fol.name,23,100) path,
    f.description description,
    
    (select name from cmn_lookups_v where language_code='en' and lookup_type='DOC_STATUS' and lookup_code=ver.status) file_status,
    (select name from cmn_lookups_v where language_code='en' and lookup_type='DOC_CATEGORY' and lookup_code=f.category) file_category,
    f.mime_type file_type,
    ver.check_in_comment
    
    from clb_dms_files f
    inner join clb_dms_folders fol on fol.id=f.parent_folder_id
    left outer join 
    (select id, 
    version_number, status, 
    file_id, check_in_comment, 
    byte_size, version_number as version, 
    created_by, created_date as version_created_date, 
    is_latest 
    from clb_dms_versions
    ) ver on ver.file_id=f.id
    INNER JOIN SRM_PROJECTS SRM ON SRM.unique_name=substring(fol.path_name+'/'+fol.name,23,abs(charindex('/',fol.path_name+'/'+fol.name ,23)-23))
    INNER JOIN PRJ_PROJECTS PRJ ON PRJ.PRID=SRM.ID
    
    WHERE 
    f.language='en' and fol.folder_type in ('ProjectFolder','StandardFolder')


  • 3.  RE: HELP - Need help with "joins" in my Query

    Posted Oct 03, 2012 12:26 PM
    Ok.....I'll take a look at what you did. Thanks!


  • 4.  RE: HELP - Need help with "joins" in my Query

    Posted Oct 03, 2012 02:29 PM
    Hi,

    I looked at this code...and I can determine the Collaboration Tab Path for the Documents.

    However, you mentioned a sub-query to join the CMN_SEC_USERS...can you provide an example? I'm still struggling with this. Thanks!


  • 5.  RE: HELP - Need help with "joins" in my Query

    Posted Oct 04, 2012 02:07 AM
    e.g., instead of
    (select full_name from srm_resources where user_id=f.owner_id) author,

    you can use this
    (select user_name from cmn_sec_users where id=f.owner_id) author,


    NJ


  • 6.  RE: HELP - Need help with "joins" in my Query

    Posted Oct 04, 2012 05:51 AM
    An example of the sub-query is in the column Author in the code I posted - the giveaway is that it's a select statement enclosed in () underneath the main select clause. Within your overall select statement you are doing another select statement, using a value from the main query (in this case owner_id from clb_dms_files) .

    My example links to SRM_Resources to display the column Full_Name from that table, and NJ's equally suitable alternative links to cmn_sec_users to get the user_name column from there. The key is that both statements take owner_id from the file table in the main part of the query.

    The only difference will be in the output, assuming your username convention is not "last name, first name". For example in my organisation I would get something like the following:

    (select full_name from srm_resources where user_id=f.owner_id) ===> would give me "Smith, John"
    (select user_name from cmn_sec_users where id=f.owner_id) author ===> would give me e.g. "john_smith"


  • 7.  RE: HELP - Need help with "joins" in my Query

    Posted Oct 04, 2012 11:50 AM
    Hi NJ/Owen:


    Ugh....I'm confused...or maybe just burned out from this effort. I don't understand where you two are suggesting this statement be placed in my existing Query. Can one of you please insert your suggested statement in my query below? (I need the list asap - for a meeting in 30 mins.) Thanks!

    SELECT
    INV.NAME INV_PROJECT_NAME,
    INV.CODE PROJECT_ID,
    VER.VERSION_NUMBER VERSION,
    VER.LAST_UPDATED_DATE LAST_UPDA,
    VER.BYTE_SIZE BYTE_SIZE,
    VER.IS_LATEST VER_IS_LATEST,
    FLD.PATH_NAME PATH,
    FIL.NAME FIL_NAME

    FROM CLB_DMS_VERSIONS VER
    left JOIN CLB_DMS_FILES FIL ON VER.FILE_ID = FIL.ID
    left JOIN CLB_DMS_FOLDERS FLD ON FIL.PARENT_FOLDER_ID = FLD.ID
    left JOIN CLB_DMS_FILES FIL ON VER.FILE_NAME = FIL.NAME
    left JOIN INV_INVESTMENTS INV ON FLD.ASSOC_OBJ_ID = INV.ID

    where trunc(ver.last_updated_date) < '2011-09-01'
    and ver.is_latest=0


  • 8.  RE: HELP - Need help with "joins" in my Query

    Posted Oct 05, 2012 06:30 AM
    You want something like this

    SELECT
    INV.NAME INV_PROJECT_NAME,
    INV.CODE PROJECT_ID,
    VER.VERSION_NUMBER VERSION,
    VER.LAST_UPDATED_DATE LAST_UPDA,
    VER.BYTE_SIZE BYTE_SIZE,
    VER.IS_LATEST VER_IS_LATEST,
    FLD.PATH_NAME PATH,
    FIL.NAME FIL_NAME,
    (select full_name from srm_resources where user_id = ver.created_by) as version_created_by

    FROM CLB_DMS_VERSIONS VER
    left JOIN CLB_DMS_FILES FIL ON VER.FILE_ID = FIL.ID
    left JOIN CLB_DMS_FOLDERS FLD ON FIL.PARENT_FOLDER_ID = FLD.ID
    left JOIN CLB_DMS_FILES FIL ON VER.FILE_NAME = FIL.NAME
    left JOIN INV_INVESTMENTS INV ON FLD.ASSOC_OBJ_ID = INV.ID

    where trunc(ver.last_updated_date) < '2011-09-01'
    and ver.is_latest=0

    Here's some information on how sub-queries are constructed in MS-SQL which may be of use.


  • 9.  RE: HELP - Need help with "joins" in my Query
    Best Answer

     
    Posted Oct 09, 2012 02:39 PM
    Hi mscann,

    Were you able to resolve your issue with NJ and Owen's suggestions? If so please mark the appropriate posts as Accepted Solution.

    Thanks!
    Chris