Functions in SqlServer2K

  • Under sa login, I am NOT able to create a function in a particular database (Let us call it 'X'). It gives me some "syntax error" even while I check its syntax. When I execute the same sql-string in the Master database it executes fine and the function created is usable.

    Sa is the dbo of the Database 'X'. Does anybody know what could be the reason?

  • Can you post the code around and including where QA is telling you there is a syntax error?

    K. Brian Kelley

    http://www.truthsolutions.com/

    Author: Start to Finish Guide to SQL Server Performance Monitoring

    http://www.netimpress.com/shop/product.asp?ProductID=NI-SQL1

    K. Brian Kelley
    @kbriankelley

  • CREATE FUNCTION CubicVolume

    -- Input dimensions in centimeters

    (@CubeLength decimal(4,1), @CubeWidth decimal(4,1),

    @CubeHeight decimal(4,1) )

    RETURNS decimal(12,3) -- Cubic Centimeters.

    AS

    BEGIN

    RETURN ( @CubeLength * @CubeWidth * @CubeHeight )

    END

    The above function is from books online. It gives a syntax error in Databse X, but executes fine in master (both under sa)

  • Here is the error message from isqlw

    Server: Msg 170, Level 15, State 1, Line 1

    Line 1: Incorrect syntax near 'FUNCTION'.

    Server: Msg 137, Level 15, State 1, Line 8

    Must declare the variable '@CubeLength'.

  • What is the compatibility level of your database? Should be 80 for functions to work.

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

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