Link to home
Start Free TrialLog in
Avatar of SQLSearcher
SQLSearcher

asked on

Oracle Stored Procedure for User Account data

Hello Experts Exchange
I need help to write a Oracle store procedure, so I can call it in my SSRS report I am developing.

In my SSRS report I have the user's AD account name, if the AD Account name is in query1 I want it to return the sites for that account.  If however the AD user account is not in query1 I want all site information to come back which is query2.

This is query1.
Select
'AD_' || substr(Loc_Loc_Code, -3) as UserName,Loc_ID, Loc_Name
        from LOCATION_GROUP_TYPES t, LOCATION_GROUPS g, locations l
        where t.LGT_TYPE = 'R' and t.LGT_REGION is not null
        and t.LGT_ID = g.LG_LGT_ID 
        and LG_LOC_ID = l.LOC_ID
        and (LOC_DATE_CLOSED is null or to_char(LOC_DATE_CLOSED,'YYYY')  = :Year)
        and l.loc_loc_ty_id = 4
        and t.LGT_DESCRIPTION <> 'ADMINISTRATION'
        and 'AD_' || substr(Loc_Loc_Code, -3) = :UserName
Union All
Select
LGT_AD_USERNAME as UserName,Loc_ID, Loc_Name
        from LOCATION_GROUP_TYPES t, LOCATION_GROUPS g, locations l
        where t.LGT_TYPE = 'R' and t.LGT_REGION is not null
        and t.LGT_ID = g.LG_LGT_ID 
        and LG_LOC_ID = l.LOC_ID
        and (LOC_DATE_CLOSED is null or to_char(LOC_DATE_CLOSED,'YYYY')  = :Year)
        and l.loc_loc_ty_id = 4
        and t.LGT_DESCRIPTION <> 'ADMINISTRATION'
        and LGT_AD_USERNAME = :UserName

Open in new window


This is query2.
Select Loc_ID, Loc_Name
        from LOCATION_GROUP_TYPES t, LOCATION_GROUPS g, locations l
        where t.LGT_TYPE = 'R' and t.LGT_REGION is not null
        and t.LGT_ID = g.LG_LGT_ID 
        and LG_LOC_ID = l.LOC_ID
        and (LOC_DATE_CLOSED is null or to_char(LOC_DATE_CLOSED,'YYYY')  = :Year)
        and l.loc_loc_ty_id = 4
        and t.LGT_DESCRIPTION <> 'ADMINISTRATION'

Open in new window


When I call the stored Procedure I want to pass the :Year Variable and the :UserName Variable.

Can anyone help me with this stored Procedure please?

Regards

SQLSearcher
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SQLSearcher
SQLSearcher

ASKER

Thank you for your help.