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 ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE 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]
GO
CREATE 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]
GO
SET IDENTITY_INSERT [dbo].[Employee] ON
GO
INSERT [dbo].[Employee] ([Id], [Name], [Latitude], [Longitude], [TypeId], [TicketsToday], [AreaId]) VALUES (1, N'Supervisor', 17.286848067916505, 78.24663132069098, 1, 5, 1)
GO
INSERT [dbo].[Employee] ([Id], [Name], [Latitude], [Longitude], [TypeId], [TicketsToday], [AreaId]) VALUES (2, N'Reader', 17.207415689708519, 78.253739445364374, 2, 5, 2)
GO
INSERT [dbo].[Employee] ([Id], [Name], [Latitude], [Longitude], [TypeId], [TicketsToday], [AreaId]) VALUES (3, N'Writer', 17.36978521081307, 78.200294359834473, 1, 9, 1)
GO
INSERT [dbo].[Employee] ([Id], [Name], [Latitude], [Longitude], [TypeId], [TicketsToday], [AreaId]) VALUES (4, N'New Join', 17.284559068738243, 78.499708338539662, 1, 5, 2)
GO
SET IDENTITY_INSERT [dbo].[Employee] OFF
GO
SET IDENTITY_INSERT [dbo].[Tickets] ON
GO
INSERT [dbo].[Tickets] ([Id], [TicketDescription], [Latitude], [Longitude], [TypeId], [AreaId]) VALUES (2, N'Emergency Ticket', 17.269480945138515, 78.3290484467444, 1, 1)
GO
INSERT [dbo].[Tickets] ([Id], [TicketDescription], [Latitude], [Longitude], [TypeId], [AreaId]) VALUES (3, N'Normal Ticket', 17.367466654347695, 78.206974995104844, 2, 1)
GO
INSERT [dbo].[Tickets] ([Id], [TicketDescription], [Latitude], [Longitude], [TypeId], [AreaId]) VALUES (4, N'Average Ticket', 17.178406092767386, 78.368524928263341, 1, 2)
GO
SET IDENTITY_INSERT [dbo].[Tickets] OFF
GO
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