Click here to Skip to main content
15,891,798 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to bind the worker information for type. The emplyee table and casualstaff table are linked. When I Choose the Permanent in ComboBox I want to display all of the parment staffs not include from the casualstaff table and when I choose the casual in combobox display all the casual staffs.

What I have tried:

SQL
DECLARE	@Staff_Type Varchar(10)

SELECT 
		'Employee Id' 	= EE.StaffID
	,	'Name'  	= RTRIM(LTRIM(EE.Name))

	FROM 
		Employee 		EE
		CasualStaff		CS
	WHERE 	(EE.StaffID=CS.StaffID
			@Staff_Type='Casual')
	OR		(EE.StaffID!=CS.StaffID
			@Staff_Type='Permanent')
Posted
Updated 20-Mar-18 3:43am

1 solution

Your question isn't completely clear, but I'm guessing you want something like this:
SQL
SELECT
    'Employee Id' = EE.StaffID,
    'Name' = RTRIM(LTRIM(EE.Name))
FROM
    Employee As EE
WHERE
(
    @Staff_Type = 'Casual'
And
    Exists
    (
        SELECT 1
        FROM CasualStaff As CS
        WHERE CS.StaffID = EE.StaffID
    )
)
Or
(
    @Staff_Type = 'Permanent'
And
    Not Exists
    (
        SELECT 1
        FROM CasualStaff As CS
        WHERE CS.StaffID = EE.StaffID
    )
)

NB: It would probably be simpler to have a flag on the Employee table to indicate the type of employee; but that depends on what else you're using the CasualStaff table for.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900