CA Service Management

 View Only
Expand all | Collapse all

SQL query for contact details page

  • 1.  SQL query for contact details page

    Posted Nov 12, 2014 04:31 PM

    Hello All,

    SD-12.7

     

    We have an requirement to display all the contact detail information and that info has to contain  the fields availble in the contact detail page by running the SQL query.for eg, for user x the results should be which group ,whch accesss type,contact type,roles etc.in which the user x have been tagged to.

     

    I have tried the below code but am not getting the results. Please help me in  framiong the query.

     

    select ca_contact.contact_uuid, last_name,zagent_id,ca_location.location_uuid, ca_location.location_name,ca_location.zlmsid, 

    ca_contact.inactive, ca_location.inactive              

    from ca_contact


    Regards,

    Mohan



  • 2.  Re: SQL query for contact details page

    Posted Nov 12, 2014 06:01 PM

    To make this more confusing, some of the information you are looking for is in the usp_contacts table.  So you will want to use a join in your statement.  I believe you would join the contact_uuid value.

     

    Hopefully someone with more knowledge will be able to jump in here.



  • 3.  Re: SQL query for contact details page

    Posted Nov 12, 2014 11:26 PM

    Assuming your custom 'z' fields were created via WSP, try this from SQL Management Studio:

     

     

    USE mdb;

     

    SELECT

        CNT.contact_uuid,

        CNT.last_name,

        USP.zagent_id,

        LOC.location_uuid,

        LOC.location_name,

        USL.zlmsid,

        CNT.inactive "Contact Active",

        LOC.inactive "Location Active"

    FROM

        ca_contact CNT

        LEFT JOIN usp_contact USP

            ON CNT.contact_uuid = USP.contact_uuid

        LEFT JOIN ca_location LOC

            ON CNT.location_uuid = LOC.location_uuid

        LEFT JOIN usp_location USL

            ON LOC.location_uuid = USL.location_uuid

     

    Regards,

    JW



  • 4.  Re: SQL query for contact details page

    Posted Nov 13, 2014 11:30 AM

    Hi ,

     

    Thanks all for your response, I have tried the above codes but we would like to have a information of the groups,roles,acces type,special handling it mist need to have most of the contact details. Please help.

     




  • 5.  Re: SQL query for contact details page

    Posted Nov 13, 2014 01:32 PM

    Mohan,

     

    You can also try looking at the Views.  There are details about these in the Administrator's Guide under View Field Descriptions

     

    See for example:

    select * from View_Contact_Full

     

    Otherwise, you can use my code for a sample and then look up the specific relationships in the Technical Reference Guide under the Data Element Dictionary, you should be able to create joins to the other tables to return the data you need.

     

    Good Luck,

    JW



  • 6.  Re: SQL query for contact details page

    Posted Nov 14, 2014 08:36 AM

    I agree with JW....

     

    Basically you need to understand how the tables are related. Without this information, the results of the SQL query might be meaningless as all you will see is UUIDs for fields that reference other tables. So first go through the Technical Reference Guide under the Data Element Dictionary to understand the MDB table structure as this will help you to build the neccessary joints.

     

    Alternatively, use a WEBI report. Should be easier to do as you just drag and drop the fields you want.



  • 7.  Re: SQL query for contact details page

    Posted Nov 15, 2014 01:02 PM

    Hi JW and Brian,

    Thanks for your suggestion, As you have said, i got little messed up with the tables and their uuids. Still am trying my level best to get the details of detail_cnt.htmpl,list_cnt.htmpl,list_cnt_role.htmpl.

     

    I am just trying to display the contact info with the groups,roles,address,notifications associated.



  • 8.  Re: SQL query for contact details page

    Posted Nov 15, 2014 09:10 PM

    I'm that case why not add all that info to the list_contact search form using Web screen painter.

     

    Is part of your requirement that the solution needs to be a sql query or would a a modified search form work?



  • 9.  Re: SQL query for contact details page

    Posted Nov 17, 2014 03:27 AM

    Hi Gbruneau,

     

    I am looking for a SQL query which will provide me the all contact's general info like access type,contact type,lms id,zlms id active...etc.. and then contact's groups,roles,notifications.etc..



  • 10.  Re: SQL query for contact details page

    Posted Nov 18, 2014 12:50 AM

    Mohan,

     

    There are many, many possible relationships from the contacts table to the rest of the database.  As Brian suggested, you are better off using the CABI reporting WEBI creator and then you can drag and drop fields because the relationships to the most common tables have been made for you and labeled with easy to understand terms.

     

    Alternatively, you can also see a ERD for the MDB at:

    https://support.ca.com/phpdocs/0/common/impcd/r11/MDBMain/Schema15/mdb/Tables/_index.htm

     

    and then navigate to the Service Desk Manager tab, and the People link:

     

     

    Good Luck,

     

    JW



  • 11.  Re: SQL query for contact details page

    Posted Nov 19, 2014 11:14 AM

    Hi, I do not find the related MDB in the Category column



  • 12.  Re: SQL query for contact details page

    Posted Nov 19, 2014 04:57 PM

    Hi All,

     

    Can anyone please tell me on which table the access type of the contact will get stored i searched in the tables acctyp,acctyp_v2 but am unable to locate all the access type details.



  • 13.  Re: SQL query for contact details page

    Posted Nov 19, 2014 05:11 PM

    Access type IDs for contacts are stored in usp_contacts.  The column c_acctyp_id hold the access type for each user.  You can look in the table acctyp_v2 to see the symbols for each access type.



  • 14.  Re: SQL query for contact details page

    Posted Nov 19, 2014 07:10 PM

    Hi Gbruneau,

     

    Thaks for the information, it helped me a lot, ihave used the below query to find the accesss type and got output.but however am unable to embed this query in my final query to have the accesstype information for the contacts. Also i didnt find any relation to display the access type of the contact . please help.

     

    select

     

    c_acctyp_id,

    acctyp_v2

    .sym

     

    FROM

     

    usp_contact INNER JOIN acctyp_v2 ON usp_contact.c_acctyp_id = acctyp_v2.id

     

    SELECT

     

    ca_contact_type.id

     

    FROM

     

    ca_contact_type INNER

    JOIN

     

     

    usp_contact

    ON ca_contact_type.id = usp_contact.c_acctyp_id

     

    Final Query:

    SELECT ca_contact.first_name,
    ca_contact.last_name ,
    ca_contact.userid,
    ca_contact.middle_name,
    ca_contact.email_address,
    ca_contact_type.name as ContactType


    FROM ca_contact  INNER JOIN ca_contact_type ON

    ca_contact_type.id = ca_contact.contact_type

    where first_name!=''

     

    I have tried using the below but am not getting the proper results, it is dispalying duplicate access type values which is taking long time and producing improper data

     

     

    SELECT

     

    top 10 * , ca_contact.first_name

    ,

     

     

    ca_contact

    .last_name ,

     

    ca_contact

    .userid,

     

    ca_contact

    .middle_name,

     

    ca_contact

    .email_address,

     

    ca_contact_type

    .name as ContactType,

     

    usp_contact

    .c_acctyp_id

     

    ,

     

    acctyp_v2.sym

     

    FROM

     

    ca_contact INNER JOIN ca_contact_type ON ca_contact_type.id = ca_contact.contact_type

     

    INNER

     

    JOIN usp_contact ON ca_contact_type.id = usp_contact.c_acctyp_id

     

    INNER

     

    JOIN ca_contact

    --on acctyp_v2.id = usp_contact.c_acctyp_id

     

     

    where

     

    first_name!=''



  • 15.  Re: SQL query for contact details page

    Posted Nov 19, 2014 09:15 PM

    You are joining ca_contact and usp_contact on two different ‘type’ columns – naturally this produces spurious data (in fact it’s only because some of the IDs in these unrelated tables overlap that it produces any data at all).

     

    The field  ‘contact_type’ in ca_contact is an FK to table ca_contact_type (‘Employee’, ‘Analyst’, ‘Customer’ etc), whereas c_acctyp_id in usp_contact is an FK to table acctyp_v2 (the Access Types).

     

    Instead of ‘inner join usp_contact on ca_contact.type_id = usp_contact.c_acctyp_id’  you need

     

    ‘join usp_contact on ca_contact.contact_uuid = usp_contact.contact_uuid’

     

    To write any SQL linking tables like this you need to develop a detailed understanding of the schema.  Follow the relationships through in the SDM Technical Reference Manual, inspect the foreign key relationships using SQL Enterprise Manager and sanity check your queries against what the SDM system shows.

     

    Regards,

    James



  • 16.  Re: SQL query for contact details page

    Broadcom Employee
    Posted Nov 19, 2014 09:25 PM

    Hi Mohan,

    Probably you may also use this below command to get to know how each table are interrelated using bop_sinfo command.

    Ex: For contacts

    bop_sinfo -d cnt >cnt.txt

     

    Cnt.txt will give you all the details.

     

    ~vinod.



  • 17.  Re: SQL query for contact details page

    Posted Nov 19, 2014 09:37 PM

    Try this, which is your last query above re-written with the joins corrected.  Hopefully this will point you in the right direction!  Note especially the join between ca_contact and usp_contact, which is needed to allow the join between usp_contact and acctyp_V2.  There must be some history behind the splitting of the contact details between ca_contact and usp_contact, but I don't know what it is.

     

    SELECT

    C.first_name

    ,C.middle_name

    ,C.last_name

    ,C.userid

    ,C.email_address

    ,T.name as ContactType

    ,A.sym as AccessType

    FROM

      ca_contact C JOIN ca_contact_type T  ON C.contact_type = T.id

         JOIN usp_contact U  ON C.contact_uuid = U.contact_uuid

         JOIN acctyp_V2 A   ON U.c_acctyp_id = A.id



  • 18.  Re: SQL query for contact details page
    Best Answer

    Posted Nov 20, 2014 04:56 PM

    Hello All,

     

    Thanks all for your help, I have framed the below SQL query for my requirement and it works cool,

     

     

    SELECT ca_contact.first_name,
    ca_contact.last_name ,
    ca_contact.userid,
    ca_contact.middle_name,
    ca_contact.inactive as Active,
    ca_contact.email_address,
    ca_contact_type.name as ContactType,
    usp_contact.c_acctyp_id,
    acctyp_v2.sym as AccessType,
    usp_role.name as rolename


    FROM ca_contact  INNER JOIN ca_contact_type ON ca_contact_type.id = ca_contact.contact_type INNER JOIN usp_contact ON ca_contact.contact_uuid = usp_contact.contact_uuid
    INNER JOIN  acctyp_v2 ON usp_contact.c_acctyp_id = acctyp_v2.id INNER JOIN usp_cnt_role ON usp_contact.contact_uuid= usp_cnt_role.contact
    INNER JOIN  usp_role ON usp_cnt_role.role_obj = usp_role.id


    where first_name!='' and ca_contact.inactive = '0'



  • 19.  Re: SQL query for contact details page

    Posted Jun 07, 2018 04:28 AM

    Hi Mohansrinivas,

    I need Location, Organization,Telephone number,Group fields with this report.

    Can you please suggest me for query ? What should be the proper query for this?

     

    Regards,

    Jagatjyoti Dash



  • 20.  Re: SQL query for contact details page

    Posted Aug 24, 2017 11:25 AM

    Here is a updated sql query from the previous post, the list CA contact information, along with email, group membership and etc.

     

    DECLARE @Contact nvarchar(max) = '%'
    DECLARE @Group nvarchar(max) = '%'
    DECLARE @Location nvarchar(max) = '%dallas%'
    DECLARE @CN nvarchar(max) = '%'

    select
     u.first_name + ' ' + u.last_name as [CA Contact]
     ,ct.name as [Contact_Type]
     ,r.sym as [Access_Type]
     ,u.UserID
     ,u.Email_Address
     ,lg.Last_Login_Time
     ,l.Location_name as Location
     ,grp.Group_Membership
     ,ldap.LDAP_DN
    --,u.*
    from ca_contact u
    -- ldap_dn
    join usp_contact ldap on ldap.contact_uuid = u.contact_uuid
    -- contact type
    left join ca_contact_type ct on ct.id = u.contact_type
    -- contact role
    left join acctyp_V2 r on r.id = ldap.c_acctyp_id
    -- location
    left join ca_location l on l.location_uuid = u.location_uuid
    -- last login
    left join (
     select contact, dateadd(ss,MAX(s.login_time)+32400,'1/1/1970') as Last_Login_Time from session_log s group by contact
     ) lg on lg.contact = u.contact_uuid
    -- group membership
    left join (
     select distinct gm.member,
     substring(
      (
       select ', '+g1.last_name as [text()]
       from view_group g1
       join grpmem gm1 on gm1.group_id = g1.contact_uuid
       where gm1.member = gm.member and g1.inactive = 0
       order by gm1.member
       for XML PATH ('')
      ), 2, 1000) [Group_Membership]
     from view_group g
     join grpmem gm on gm.group_id = g.contact_uuid
     -- list active groups only
     where g.inactive = 0
     ) grp on grp.member = u.contact_uuid
    where
    -- active contacts only
    u.inactive = 0
    -- filter by Contact Name
    and u.first_name + ' ' + u.last_name like @Contact
    --  filter by Group Membership
    and isnull(grp.Group_Membership,'') like @Group
    --  filter by Location
    and isnull(l.Location_name ,'') like @Location
    --  filter by LDAP_DN
    and isnull(ldap.LDAP_DN,'') like @CN
    -- order by last name, first name
    order by u.last_name, u.first_name