Dears,
I have one issue and I am not able to write proper query for this.
I have 2 tables called Employees and Tickets
/****** Object: Table [dbo].[Tickets] Script Date: 3/14/2022 12:30:28 AM ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[Tickets]([Id] [int] IDENTITY(1,1) NOT NULL,[TicketDescription] [nvarchar](500) NOT NULL,[Latitude] [float] NULL,[Longitude] [float] NULL,[TypeId] [int] NULL,[AreaId] [int] NULL,CONSTRAINT [PK_Tickets] PRIMARY KEY CLUSTERED([Id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOCREATE TABLE [dbo].[Employee]([Id] [int] IDENTITY(1,1) NOT NULL,[Name] [nvarchar](100) NULL,[Latitude] [float] NULL,[Longitude] [float] NULL,[TypeId] [int] NULL,[TicketsToday] [int] NULL,[AreaId] [int] NULL,CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED([Id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOSET IDENTITY_INSERT [dbo].[Employee] ONGOINSERT [dbo].[Employee] ([Id], [Name], [Latitude], [Longitude], [TypeId], [TicketsToday], [AreaId]) VALUES (1, N'Supervisor', 17.286848067916505, 78.24663132069098, 1, 5, 1)GOINSERT [dbo].[Employee] ([Id], [Name], [Latitude], [Longitude], [TypeId], [TicketsToday], [AreaId]) VALUES (2, N'Reader', 17.207415689708519, 78.253739445364374, 2, 5, 2)GOINSERT [dbo].[Employee] ([Id], [Name], [Latitude], [Longitude], [TypeId], [TicketsToday], [AreaId]) VALUES (3, N'Writer', 17.36978521081307, 78.200294359834473, 1, 9, 1)GOINSERT [dbo].[Employee] ([Id], [Name], [Latitude], [Longitude], [TypeId], [TicketsToday], [AreaId]) VALUES (4, N'New Join', 17.284559068738243, 78.499708338539662, 1, 5, 2)GOSET IDENTITY_INSERT [dbo].[Employee] OFFGOSET IDENTITY_INSERT [dbo].[Tickets] ONGOINSERT [dbo].[Tickets] ([Id], [TicketDescription], [Latitude], [Longitude], [TypeId], [AreaId]) VALUES (2, N'Emergency Ticket', 17.269480945138515, 78.3290484467444, 1, 1)GOINSERT [dbo].[Tickets] ([Id], [TicketDescription], [Latitude], [Longitude], [TypeId], [AreaId]) VALUES (3, N'Normal Ticket', 17.367466654347695, 78.206974995104844, 2, 1)GOINSERT [dbo].[Tickets] ([Id], [TicketDescription], [Latitude], [Longitude], [TypeId], [AreaId]) VALUES (4, N'Average Ticket', 17.178406092767386, 78.368524928263341, 1, 2)GOSET IDENTITY_INSERT [dbo].[Tickets] OFFGO
When the user load the tickets I have to filter the employee for each ticket means the system should provide suggestions of the employee who is near to ticket raised area
Conditions:
Location
TypeId
AreaId
TodaysTickets
User can select all or some of the above criteria
1 If Location is selected then
. Sort employees location with tickets location. Display the nearest employee to the ticket location
- If TypeId is selected then
TypeId of Employee should match with ticket typeid - If TodaysTickets Selected
Get the employee who have less number of TodaysTicket Value - AreaId Selcetd then check the Employee Area Id with Tickets
I could able to sort based on location but after sorting location now I have to filter employee whose AreaId, TypeId matches the ticket records and Whoever have least todaytickets.
So for each ticket the system provides its suggestion based on the above criteria
The final result needed something like this
TicketDescription EmployeeName
Normal Ticket Reader
Emergency Ticket Supervisor