Declaring data type in a function AS...

  • Take a function like this: CREATE FUNCTION dbo.fn.example1(@foobar AS INT)

    What happens if this function is called like this (with a non-integer)? dbo.fn.example1(1.1)

    And how about this dbo.fn.example1(wordsblah) ?

  • Why don't you test it and find out? Likely you'll remember it far better than if someone just gives you the answer.

    CREATE FUNCTION TestingDataTypes (@Blah INT)

    RETURNS INT

    AS

    BEGIN

    RETURN @Blah

    END

    GO

    SELECT dbo.TestingDataTypes(1.1)

    GO

    SELECT dbo.TestingDataTypes(wordsblah)

    GO

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Golfer22 (7/4/2012)


    And how about this dbo.fn.example1(wordsblah) ?

    Keep in mind that in SQL Server, variables are declared with a @ character before the name. Sometimes I forget that because I work with Oracle and DB2 a lot.

    Best regards,

    Andre Guerreiro Neto

    Database Analyst
    http://www.softplan.com.br
    MCITPx1/MCTSx2/MCSE/MCSA

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

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