如何使用用戶定義的函數?

[英]How can I use user defined functions?


I have a table Users, so some rows specially in field Full Name are in different upper/lower case, so i found this function:

我有一個表用戶,所以特別是字段全名的一些行是大小寫不同的,所以我找到了這個函數:

CREATE function properCase(@texto varchar(8000)) returns varchar(8000) as   
begin   
    --declare @texto = 'hola'  
    set @texto = lower(@texto)   

    declare @i int   
    set @i = ascii('a')   

    while @i <= ascii('z')   
    begin   

        set @texto = replace(@texto, ' ' + char(@i), ' ' + char(@i-32))   
        set @i = @i + 1   
    end   

    set @texto = char(ascii(left(@texto, 1))-32) + right(@texto, len(@texto)-1)   

    return @texto   
end  

How can I use this function to update or select the "fullname" field from my user table?

如何使用此功能更新或從我的用戶表中選擇“fullname”字段?

2 个解决方案

#1


SELECT dbo.properCase(fullname) FROM [user]

and

UPDATE [user] SET fullname = dbo.properCase(fullname)

#2


SELECT dbo.properCase(FullName) FROM [User]

and:

UPDATE [User] SET FullName = dbo.properCase(FullName)

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/02/10/f71694bbf10ffe9a874f1db01cca6317.html



 
  © 2014-2022 ITdaan.com 联系我们: