Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Posts
    119

    Unanswered: How to call a function from a column formula in my MS SQL table

    Good day!

    What is the syntax on calling a function from a column formula in an MS SQL table.

    I created a table, one column's value will be coming from a function. And at the same time, I will pass parameters to the function. How do I do this? Is this correct?

    SELECT dbo.FunctionName([Parameter1, Parameter2])
    But i can't save the table, "Error validating the formula".

    Pls. help
    Thanks a lot.

  2. #2
    Join Date
    Nov 2002
    Posts
    272
    <edit> Never mind, I misunderstood what you are doing.
    I'm afraid I have no advice.

  3. #3
    Join Date
    Dec 2002
    Posts
    1,245
    It may or may not work depending on what you are trying to do. You can use a udf and define the result as simply:

    Code:
    DEFAULT (dbo.udfMyFunction('SomeParam','OtherParam'))
    However, SomeParam and OtherParam must be constants or system functions (like suser_sname() or host_name()). They can't be names of columns in your table.

    Regards,

    hmscott
    Have you hugged your backup today?

  4. #4
    Join Date
    Mar 2007
    Location
    Holmestrand, Norway
    Posts
    332
    Or perhaps he want a computed column:

    create table foo (
    id int,
    hash as dbo.getHash(id),
    ...
    );
    Ole Kristian Velstadbråten Bangås - Virinco - MSSQL.no - Facebook - Twitter

Posting Permissions

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