Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Posts
    15

    Unanswered: SQL function execution

    How can I execute a function on MS SQL Server ?

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    It depends on what type of function it is.

    Look up "Executing User-defined Functions (Database Engine)" in BoL
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    58
    for most simple functions you have an input
    select dbo.functionname ('myinput')

    Here is an example
    Open query analyzer and create this function by running this script
    --This function takes any word and performs and Initial Capital on the word.
    then run the commented out line

    SET QUOTED_IDENTIFIER ON
    GO
    SET ANSI_NULLS OFF
    GO

    --select dbo.f_InitCap ('happy')


    CREATE FUNCTION [dbo].[f_InitCap] ( @InputString varchar(4000) )
    RETURNS VARCHAR(4000)
    AS
    BEGIN

    DECLARE @Index INT
    DECLARE @Char CHAR(1)
    DECLARE @PrevChar CHAR(1)
    DECLARE @OutputString VARCHAR(255)

    SET @OutputString = LOWER(@InputString)
    SET @Index = 1

    WHILE @Index <= LEN(@InputString)
    BEGIN
    SET @Char = SUBSTRING(@InputString, @Index, 1)
    SET @PrevChar = CASE WHEN @Index = 1 THEN ' '
    ELSE SUBSTRING(@InputString, @Index - 1, 1)
    END

    IF @PrevChar IN (' ', ';', ':', '!', '?', ',', '.', '_', '-', '/', '&', '''', '(')
    BEGIN
    IF @PrevChar != '''' OR UPPER(@Char) != 'S'
    SET @OutputString = STUFF(@OutputString, @Index, 1, UPPER(@Char))
    END

    SET @Index = @Index + 1
    END

    RETURN @OutputString

    END
    GO
    SET QUOTED_IDENTIFIER OFF
    GO
    SET ANSI_NULLS ON
    GO
    Last edited by burkular; 04-12-09 at 13:15.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •