我有一个程序,我想用它来搜索xml列并返回我搜索的值。现在我只想让它返回值本身。就像现在一样,它返回正确的预期行数,但返回的值为null!我添加了演员,但它返回相同!
有关如何获取搜索字符串而不仅仅是null的任何想法?谢谢!
CREATE PROCEDURE [dbo].[FindString]
@findString NVARCHAR(100)
AS
BEGIN
SET NOCOUNT ON
;WITH XMLNAMESPACES (Default 'http://www.w3.org/2001/XMLSchema' )
SELECT CAST(x.value('Value[1]', 'varchar(30)') As varchar(30)) As Value
FROM dbo.XmlTable x
CROSS APPLY x.XmlDocument.nodes('/*') a(x)
WHERE XmlDocument.exist('//*/text()[contains(., sql:variable("@findString"))]') = 1
RETURN
END
GO
答案 0 :(得分:1)
这有用吗?
CREATE PROCEDURE [dbo].[FindString]
@findString NVARCHAR(100)
AS
BEGIN
SET NOCOUNT ON
;WITH XMLNAMESPACES (Default 'http://www.w3.org/2001/XMLSchema' )
SELECT CAST(x.value('.', 'varchar(30)') As varchar(30)) As Value
FROM dbo.XmlTable x
CROSS APPLY x.XmlDocument.nodes('//*[contains(text()[1], sql:variable("@findString"))]') a(x)
RETURN
END
GO