I have an XML column in my SQL Server 2008 table. What I'm trying to do is for a given parameter to my stored procedure strip out any spaces (using REPLACE
) in the param and use this in the WHERE
criteria but then using the XQuery exist clause also use the REPLACE
method on the xml data:
-- Add the parameters for the stored procedure here
@PostCode varchar(20) = ''
AS
BEGIN
-- strip out any spaces from the post code param
SET @PostCode = REPLACE(@PostCode, ' ','')
SELECT TOP 1 *
FROM sd_LocalAuthorities
WHERE PostCodes.exist(N'REPLACE(/PostCodes/PostCode/text(), '' '','''')[. = sql:variable("@PostCode")]') = 1
END
I'm getting the error at XQuery sd_LocalAuthorities.PostCodes.exist()
There is no function '{http://www.w3.org/2004/07/xpath-functions}:REPLACE()
when running the procedure. Is there any alternatives to REPLACE()
I can use to strip out spaces just for this WHERE
criteria, I don't want to be modifying the table itself.