How to call/execute functions create by users

  • Hello

    I read a script to create a function to return the SQL version :

    IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[fnGetSQLBuild]') AND xtype in (N'FN', N'IF', N'TF'))

    DROP FUNCTION [dbo].[fnGetSQLBuild]

    GO

    CREATE FUNCTION [dbo].[fnGetSQLBuild] () RETURNS nvarchar(20) AS

    BEGIN

    RETURN SUBSTRING(@@VERSION, CHARINDEX( N' - ', @@VERSION)+3, CHARINDEX(N' (', @@VERSION) - (CHARINDEX( N' - ', @@VERSION)+3))

    END

    Now, how can i run this function to show the result on grid in query analyser.

    Many thanks

    Luis Santos

  • Make sure you grant permissions on your function first.

    declare @SQLBuild nvarchar(20)

    set @SQLBuild = dbo.fnGetSQLBuild()

    print @SQLBuild

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • ... or just:

    select dbo.fnGetSQLBuild()

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

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