Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2002
    Posts
    229

    Unanswered: Can't find my UDF

    Sometimes the simplest things are the most difficult... I'm creating a
    UDF as below, then executing it but all I get is that the object does not exist. I must be missing something very basic here...

    CREATE function dbo.GetColumnLength(@vcTableName varchar(50), @vcColumnName varchar(50)) returns smallint
    as
    begin
    declare @intLength as smallint
    select @intLength=sysC.prec from syscolumns sysC, sysobjects sysO
    where sysC.Id = sysO.Id AND sysO.xtype ='U' And
    sysO.Name = @vcTableName AND
    sysC.Name = @vcColumnName
    return @intLength
    End
    GO
    select top 2 * from player, dbo.GetColumnLength('playerdetails','email')

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Odd. Can you see the UDF in Enterprise Manager?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Nov 2005
    Location
    San Francisco, CA
    Posts
    506
    Quote Originally Posted by Coolberg

    select top 2 * from player, dbo.GetColumnLength('playerdetails','email')
    Check the above statement.
    I think it should be ...
    select top 2 *,dbo.GetColumnLength('playerdetails','email') from player

    And yes it just working fine ....
    Joydeep

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by blindman
    Odd.
    Odd?

    Didn't you just answer this interview question a short while ago?

    It's not retuning a table so it can't be in the FROM clause, and in any event, what you're doing doesn't make much sense.

    Just what is it you are trying to accomplish?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    What I meant was, "Odd" that I didn't notice he had the function in his WHERE clause...

    Still odd that he would recieve an error stating that the object doesn't exist...

    Maybe what he wants is this:
    select top 2 *, dbo.GetColumnLength('playerdetails','email') from player
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  6. #6
    Join Date
    Jul 2002
    Posts
    229
    Thanks... I know I was tired at work today, but this mistake was just too much ;-)

  7. #7
    Join Date
    Jul 2002
    Posts
    229
    The code I posted was just an example, it's not the final UDF. It was simply just the only UDF code I had at hand.

    Just as a principle, I should be able to have a UDF call in the table list, shouldn't I ?

  8. #8
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Yes, if the UDF returns a table rather than a scalar result.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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