views:

204

answers:

2

I have the following.

SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO


ALTER  FUNCTION doublequotestring(@str nvarchar(1998)) RETURNS nvarchar(4000) AS
   BEGIN
      DECLARE @ret nvarchar(4000),
              @sq  char(1)
      SELECT @sq = '"'
      SELECT @ret = replace(@str, @sq, @sq + @sq)
      RETURN(@sq + @ret + @sq)
   END


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

Is there another way?

+1  A: 

Why not simply:

alter function doublequotestring(@str nvarchar(1998)) returns nvarchar(4000)
begin
 return '"' + replace(@str, '"', '""') + '"'
end
Guffa
+1  A: 

Use the QUOTENAME function.

GSerg
Thanks for reminding me.
Saif Khan