在这个sql server存储过程中查询
SELECT HireResponseID,
HireResponse,
DateResponse,
Comments,
YearFileOpened,
file_number,
isCaseOpen,
last_update,
isConfidential,
date_created,
OurClient,
TheirClient,
ProjectName,
description,
lawyer_lastname,
lawyer_firstname,
Conflicts.ConflictID
FROM Hire_Response,
Conflicts,
Lawyers
WHERE Hire_Response.ConflictID=Conflicts.ConflictID
AND Lawyers.lawyerID=Conflicts.lawyerID
AND firmID = @FirmID
AND HireID IN @HireID
AND isStillaConflict = 1
ORDER BY file_number,
TheirClient,
OurClient,
lawyer_lastname,
lawyer_firstname
参数@HireID
是一个逗号分隔的整数字符串(它周围没有括号)。我想检查HireID
字符串中是否有@HireID
整数。但我不知道如何解析这个。
有人可以帮忙吗?
由于
答案 0 :(得分:0)
如果我理解你的问题,你想找到HireID在列表@HireID中的行。如果HireID是一致的长度,并且列表是分隔的,那么您可以使用:
AND @HireID LIKE '%'+CAST(HireID AS VARCHAR(5))+'%'
你也可以使用CHARINDEX:
AND CHARINDEX(HireID,@HireID) > 0
编辑:要考虑长度不一致,您可以使用:
AND (@HireID LIKE '%'+CAST(HireID AS VARCHAR(5))+',%'
OR @HireID LIKE '%,'+CAST(HireID AS VARCHAR(5))+'%')
答案 1 :(得分:0)
试试这个 -
DECLARE @HireID VARCHAR(100)
SELECT @HireID = '2,18'
;WITH cte AS
(
SELECT ID = t.c.value('.', 'INT')
FROM (
SELECT txml = CAST('<t>' + REPLACE(@HireID, ',', '</t><t>') + '</t>' AS XML)
) a
CROSS APPLY txml.nodes('/t') AS t(c)
)
SELECT *
FROM Hire_Response
JOIN Conflicts ON Hire_Response.ConflictID = Conflicts.ConflictID
JOIN Lawyers ON Lawyers.lawyerID = Conflicts.lawyerID
WHERE firmID = @FirmID
AND isStillaConflict = 1
AND HireID in (SELECT ID FROM cte)
ORDER BY file_number, TheirClient, OurClient, lawyer_lastname, lawyer_firstname