[英]Basic SQL UDF creation
After reading far too much on the subject, I'm clueless how to write a UDF, and where to save it. 在阅读了过多的主题之后,我不知道如何编写UDF以及将其保存在何处。
Instead of writing the same nested REPLACE() numerous times in several other scripts, I would like to be able to call it as I need, something like: 与其在多个其他脚本中多次编写同一个嵌套的REPLACE(),不如希望我可以调用它,例如:
Targ.Name = dbo.fn_add_sym( isnull(Targ.Name, Src.Name) )
I have the following function, but I haven't been able to test it, since I don't know where to put it. 我具有以下功能,但由于不知道放置位置,因此无法对其进行测试。
CREATE FUNCTION dbo.fn_add_sym( @string NVARCHAR(max) )
RETURNS NVARCHAR(max)
WITH SCHEMABINDING
AS
begin
return
@string = REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE(@string, N'%2b', N'+')
, N'%2d', N'-')
, N'%3d', N'=')
, N'%22', N'"')
, N'%5f', N'_')
,'"', N'"')
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.