I am stuck while creating query for this. Below are the tables.
CREATE TABLE [dbo].[Mst_Conflict_Roles]
(
[CRLm_ID] [dbo].[ITS_BID] IDENTITY(1,1) NOT NULL,
[CRLm_Roles] [varchar](10) NOT NULL,
[CRLm_Description] [varchar](200) NULL,
[CRLm_Added_By] [dbo].[ITS_UserID] NOT NULL,
[CRLm_Added_Dt] [dbo].[ITS_Datetime] NOT NULL,
[CRLm_Last_Updated_By] [dbo].[ITS_UserID] NULL,
[CRLm_Last_Updated_Dt] [dbo].[ITS_Datetime] NULL,
[CRLm_data_del] [dbo].[ITS_TID] NOT NULL,
CONSTRAINT [PK_Mst_Conflict_Roles]
PRIMARY KEY CLUSTERED ([CRLm_ID] ASC)
) ON [PRIMARY]
INSERT INTO [Mst_Conflict_Roles]
VALUES ('2,113', 'Scheduler - Auditor', 1, GETDATE(), 1, GETDATE(), 0),
('110,113','AE - Scheduler',1,GETDATE(),1,GETDATE(),0),
('2,121','Auditor - Vendor CAP User',1,GETDATE(),1,GETDATE(),0),
('8,9','AM - AC',1,GETDATE(),1,GETDATE(),0)
declare @userRole as table(userID int, userRole int)
Insert into @userRole values (1, 2),(1, 113),(1, 8),(1, 9),(1, 50),(2, 110),(2, 50),(3, 2),(3, 121)
select * from @userRole
Logic : If user role(userRole) match the conflict table roles(CRLm_Roles) then record must be appear in output table.
Output
UserID CRLm_ID CRLm_description
1 1 2,113
1 4 8,9
3 3 2,121
Can anyone tell me how I can approach this?