我有一个显示在这里的存储过程;它在XML列中搜索类型为(TEXT
)并查找要匹配的输入参数(名字和姓氏或电话或号码)。问题是存储过程运行得非常慢,无法通过所有记录。反正有没有让它更快? (我使用了强制转换因为列是TEXT
类型将其转换为XML并替换,因为某些XMLS有额外的)
CREATE PROCEDURE [dbo].[Tracker]
@FirstName varchar(100)
,@LastName varchar(100)
,@Phone varchar(100)
,@Number varchar(100)
AS
BEGIN
SET NOCOUNT ON;
SELECT
[Id], [Type], [Response], [Modified], [Created],
[bSalesforce], [Request], [Application_Filename], [AffiliateId]
FROM
[Tracker]
WHERE
CAST(REPLACE(CAST(Request AS varchar(max)), '\"', '"') AS xml).value('(/I/Credit/LoanApp/LoanRq/Applicant/Personal/Individu
als/Individual/GivenName/FirstName/text())[1]', 'NVARCHAR(max)') = @FirstName
AND CAST(REPLACE(CAST(Request AS varchar(max)), '\"', '"') AS
xml).value('(/I/Credit/LoanApp/LoanRq/Applicant/Personal/Individu
als/Individual/GivenName/LastName/text())[1]', 'NVARCHAR(max)') = @LastName
OR CAST(REPLACE(CAST(Request AS varchar(max)), '\"', '"') AS
xml).value('(/I/Credit/LoanApp/LoanRq/Applicant/Personal/Individu
als/Individual/phone/text())[1]', 'NVARCHAR(max)') = @phone
OR CAST(REPLACE(CAST(Request AS varchar(max)), '\"', '"') AS xml).value('(/I/Credit/LoanApp/LoanRq/Applicant/Routing/From/Number/text())[1]', 'NVARCHAR(max)') = @Number
END