Чтобы ответить на ваш буквальный вопрос, это было бы что-то вроде ...
SELECT
tickets.TicketNumber,
tickets.Description,
tickets.departmentname,
tickets.devicename,
tickets.creatorname,
tickets.creationdate,
tickets.ExecutionDate,
tickets.closedate
stateName,
PriorityName,
FullName,
FROM
tickets
INNER Join Users On Tickets.AssignedTo = Users.UserID
INNER Join States On Tickets.StateID = States.StateID
INNER Join Priorities On Tickets.priority = Priorities.PriorityID
WHERE tickets.Description Like '%SEARCHTEXT%'
OR tickets.TicketNumber Like '%SEARCHTEXT%'
OR tickets.TicketNumber IN (SELECT TicketNumber
FROM dbo.ticketaction
WHERE ActionDescription like '%SEARCHTEXT%'
)
Лучшим решением может быть использование JOIN
в таблице ticketAction
SELECT
tickets.TicketNumber,
tickets.Description,
tickets.departmentname,
tickets.devicename,
tickets.creatorname,
tickets.creationdate,
tickets.ExecutionDate,
tickets.closedate
stateName,
PriorityName,
FullName,
FROM
tickets
INNER JOIN Users ON tickets.AssignedTo = Users.UserID
INNER JOIN States ON tickets.StateID = States.StateID
INNER JOIN Priorities ON tickets.priority = Priorities.PriorityID
INNER JOIN ticketAction ON ticket.TicketNumber = ticketAction.TicketNumber
WHERE tickets.Description Like '%SEARCHTEXT%'
OR tickets.TicketNumber Like '%SEARCHTEXT%'
OR ticketAction.ActionDescription LIKE '%SEARCHTEXT%'
(Предполагается, что в каждом билете есть ticketAction. Если это не так, используйте LEFT JOIN
)
Или EXISTS()
...
SELECT
tickets.TicketNumber,
tickets.Description,
tickets.departmentname,
tickets.devicename,
tickets.creatorname,
tickets.creationdate,
tickets.ExecutionDate,
tickets.closedate
stateName,
PriorityName,
FullName,
FROM
tickets
INNER Join Users On Tickets.AssignedTo = Users.UserID
INNER Join States On Tickets.StateID = States.StateID
INNER Join Priorities On Tickets.priority = Priorities.PriorityID
WHERE tickets.Description Like '%SEARCHTEXT%'
OR tickets.TicketNumber Like '%SEARCHTEXT%'
OR EXISTS (SELECT *
FROM dbo.ticketaction
WHERE ActionDescription like '%SEARCHTEXT%'
AND TicketNumber = tickets.TicketNumber
)