using formula in design table

  • Does anyone know how to use the formula in the design tbl (sql 2000), need to default a column to 'U' if input data is ' '(space) during insert, i tried something like IIf(column_name = ' ','U','U') and got an error. do not want to use trigger. Thanks for quick response

  • First create and test a function that does what you need, maybe something like this:

    IF EXISTS (SELECT *

    FROM sysobjects

    WHERE name = N'test_function')

    DROP FUNCTION test_function

    GO

    create FUNCTION test_function

    (@p1 varchar(10))

    RETURNS varchar(10)

    AS

    BEGIN

    declare @Temp varchar(10)

    if @p1 =' '

    select @Temp='U'

    else

    select @Temp=@p1

    return @Temp

    END

    GO

    Next, in the formula, enter this (based on the above example and assuming that whocares and col3 are varchar cols in the table):

    ([dbo].[test_function]([col3]))

    Could you explain why this will work out to be a better solution than a trigger? Are you planning to index it? Just curious!

    Andy

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

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