Please, please help me !!!!
I have a stored procedure that I need to modify. The stored procedure
is used in an Access DB program where user selects a ProjectID and
views/or can email data for different Units.
I have to make sure that if a projectid is for ‘Fire' Unit report goes
to EVERYONE in a select list and one more user
(v_ddcemployee.employee_id = 2234). If it's not ‘Fire' Unit then
report goes to EVERYONE on select list excluding this specific user.
I have tried case statement and If Else but nothing works – I don't
know how to do this
select ProgUnitName from v_progunit where ProgUnitID = 9 <=== will
return ‘Fire'
Here is my Stored procedure:
CREATE PROCEDURE sp_GetFullReportCCList
@ProjectID varchar (11) AS
SELECT v_progunit.ProgUnitName, tlkpSafetyTitle.SafetyTitleDesc,
v_ddcemployee.[Last_Name] + ', ' + v_ddcemployee.[First_Name] AS Name
FROM v_DDCemployee
INNER JOIN (tlkpSafetyTitle INNER JOIN (tblSafetyPersnl INNER JOIN
v_progunit ON tblSafetyPersnl.ProgUnitID = v_progunit.ProgUnitID) ON
tlkpSafetyTitle.SafetyTitleID = tblSafetyPersnl.SafetyTitleID) ON
v_DDCemployee.employee_id = tblSafetyPersnl.Employee_ID
WHERE tblSafetyPersnl.SafetyTitleID In (5,6,7,8,10,11,13,15,19)
AND v_progunit.Division='S'
OR tblSafetyPersnl.SafetyTitleID In (5,7,11,13,14,15,19,20)
AND v_progunit.Division='I'
UNION
SELECT v_progunit.ProgUnitName, tlkpProjectTitle.ProjectTitleDesc AS
SafetyTitleDesc,
v_ddcemployee.[Last_Name] + ', ' + v_ddcemployee.[First_Name] AS Name
FROM v_progunit
INNER JOIN (((tblProjectTeam INNER JOIN tlkpProjectTitle ON
tblProjectTeam.ProjectTitleID = tlkpProjectTitle.ProjectTitleID) INNER
JOIN v_tblprojectid ON tblProjectTeam.ProjectID =
v_tblprojectid.ProjectID)
INNER JOIN v_DDCemployee ON tblProjectTeam.loginid =
v_DDCemployee.loginID) ON v_progunit.ProgUnitName =
v_tblprojectid.Unit_Name
WHERE v_progunit.Division='S'
AND v_tblprojectid.ProjectID=@ProjectID
OR v_progunit.Division='I'
AND v_tblprojectid.ProjectID=@ProjectID
GO
I will be forever grateful to everyone that helps me :)
Sonya 1 1443
Try this, add the employee_ID to the select, make sure you always get
the employee_id = 2234 and use a derived table.
Select DISTINCT ProgUnitName,SafetyTitleDesc,Name
from ( SELECT v_progunit.ProgUnitName,
tlkpSafetyTitle.SafetyTitleDesc,
v_ddcemployee.[Last_Name] + ', ' + v_ddcemployee.[First_Name] AS Name
,v_DDCEmployee.Employee_ID
FROM v_DDCemployee
INNER JOIN (tlkpSafetyTitle INNER JOIN (tblSafetyPersnl INNER JOIN
v_progunit ON tblSafetyPersnl.ProgUnitID = v_progunit.ProgUnitID) ON
tlkpSafetyTitle.SafetyTitleID = tblSafetyPersnl.SafetyTitleID) ON
v_DDCemployee.employee_id = tblSafetyPersnl.Employee_ID
WHERE tblSafetyPersnl.SafetyTitleID In (5,6,7,8,10,11,13,15,19)
AND v_progunit.Division='S'
OR tblSafetyPersnl.SafetyTitleID In (5,7,11,13,14,15,19,20)
AND v_progunit.Division='I'
UNION
SELECT v_progunit.ProgUnitName, tlkpProjectTitle.ProjectTitleDesc AS
SafetyTitleDesc,
v_ddcemployee.[Last_Name] + ', ' + v_ddcemployee.[First_Name] AS Name
,v_DDCEmployee.Employee_ID
FROM v_progunit
INNER JOIN (((tblProjectTeam INNER JOIN tlkpProjectTitle ON
tblProjectTeam.ProjectTitleID = tlkpProjectTitle.ProjectTitleID) INNER
JOIN v_tblprojectid ON tblProjectTeam.ProjectID =
v_tblprojectid.ProjectID)
INNER JOIN v_DDCemployee ON tblProjectTeam.loginid =
v_DDCemployee.loginID) ON v_progunit.ProgUnitName =
v_tblprojectid.Unit_Name
WHERE v_progunit.Division='S'
AND v_tblprojectid.ProjectID=@ProjectID
OR v_progunit.Division='I'
AND v_tblprojectid.ProjectID=@ProjectID your union selects here )
where (progUnitName = 'Fire'
UNION
*** select as above where employee_id = 2234, in
other words - always select this employee ***
)
Where ( ProgUnitName = 'Fire') or ( ProgUnitName <> 'Fire' and
employee_id <> 2234) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: berthelot samuel |
last post by:
Hi everyone,
I am currently trying to write a report based on a View of SQL Server.
Basically, I have 3 tables : Hardware, SoftwareInstalled and Software
with SoftwareInstalled that keeps track of...
|
by: Jeff Uchtman |
last post by:
Query in ASP against a MS SQL DB.
<%
Dim Sql
Dim Conn
Dim totalCount
Dim rsCount
Dim rsACount
Dim PetACount
Dim rsBCount
|
by: Kumar |
last post by:
Hi
I am trying to recreate a database under the following environments :
From: Solaris with DB2UDB version 7.2 with FP 9
To: Linux with DB2UDB version 7.2 with FP 9
It will be of really a...
|
by: Dino L. |
last post by:
How can I run stored procedure (MSSQL) ?
|
by: Siv |
last post by:
Hi,
I have a stored procedure that I want to execute and then wait in a loop
showing a timer whilst it completes and then carry on once I get
notification that it has completed. The main reason...
|
by: peaceburn |
last post by:
Hi,
I'm gonna pull my hair in the coming days with these DB2 stored
procedures.
So the issue, let's assume a simple stored procedure like this :
CREATE PROCEDURE MYSCHEMA.PROCEDURE1 ( )...
|
by: Darth Ferret |
last post by:
This thing is about to drive me crazy. I have about 50 queries in the AS400
that I need to put on a menu. Once I conquer this I have a bunch more rpg
reports that I need to pass a date to. In the...
|
by: Riaaaa |
last post by:
Pls check my code for the stored procedure which i created for the companydetails including
companyid P.K. Not Null int(4),
companyname Not Null varchar (20),
address varchar(30)
where...
|
by: SOI_0152 |
last post by:
Hi all!
Happy New Year 2008. Il hope it will bring you love and happyness
I'm new on this forum.
I wrote a stored procedure on mainframe using DB2 7.1.1 and IBM language c.
Everything works...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |