Created
September 22, 2013 22:51
-
-
Save Cyberloki/6664613 to your computer and use it in GitHub Desktop.
SQL AsXMLAttribute function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if object_id('AsXMLAttribute') IS NOT NULL | |
DROP FUNCTION [dbo].[AsXMLAttribute] | |
GO | |
CREATE FUNCTION [dbo].[AsXMLAttribute] ( | |
@text varchar(max) | |
) | |
RETURNS varchar(max) | |
AS | |
BEGIN | |
declare @res varchar(max) | |
select @res = (select @text for xml path('') ) | |
select @res = replace(@res, '"', '"') | |
select @res = replace(@res, '''', ''') | |
return @res | |
END | |
-- select dbo.AsXMLAttribute('This <here> is some ''crazy'' "stuff" & more') | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment