user defined functions & columns

  • I have created a user defined function that takes a string as input.

    EG: Create function func_new(@str varchar(20))

    returns varchar(20)

    begin

    ......

    .....

    return @str1

    end

    @STR is a table column

    How do I call this function so that all columns in the table get manipulated by the function??

  • Please provide more information on what you're trying to do.

    It's hard for us to translate

    "......

    .....

    "

    into something that "manipulates all columns in the table"

    We don't even know what table you're talking about nor what kind of "manipulation" you're trying to do.

    Please follow the first link in my signature on how to post sample data and I'm sure you'll get fast response that actually will answer your question.

    Keep in mind that we don't see what you see since we can't look over your shoulder.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Create FUNCTION [dbo].[fnRemoveBadCharacter]

    (

    @BadString nvarchar(40)

    )

    RETURNS nvarchar(40)

    AS

    BEGIN

    DECLARE @npos INTEGER

    SELECT @npos = PATINDEX('%[^a-zA-Z0-9_]%', @BadString)

    WHILE @npos > 0

    BEGIN

    SELECT @BadString = STUFF(@BadString, @npos, 1, '')

    SELECT @npos = PATINDEX('%[^a-zA-Z0-9_]%', @BadString)

    END

    This is the function I have created to remove bad characters.

    How do I call this function to update col1(nvarchar(40)) of tbl1 to remove bad characters?

  • update table1 set col1 = dbo.fnRemoveBadCharacter(col1);

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply