Quelle est la meilleure façon d'ajouter des guillemets doubles dans le serveur SQL 2000

StackOverflow https://stackoverflow.com/questions/723409

Question

J'ai ce qui suit.

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

Y at-il une autre façon?

Était-ce utile?

La solution

Utilisez la fonction QUOTENAME .

Autres conseils

Pourquoi ne pas simplement:

alter function doublequotestring(@str nvarchar(1998)) returns nvarchar(4000)
begin
    return '"' + replace(@str, '"', '""') + '"'
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top