Non-Simple Computed Column formulas...

  • Hello... Me again...

    If I have a non-simple computed column formula like:

    (((ColumnA * ColumnB) / ColumnC) * ColumnD)

    1) Should this be a problem for SQL Server?

    It barks at me when attempting to save but it does save (it loses some parebthesis however - messing up operator precedence)

    2) Can I call a UDF from a Computed column?

    Like:

    dbo.MyFunction(ColumnA, ColumnB, etc..)

    Thanks in advance - B

  • I do not see anything there that would be a problem. And since the precedence of * and / are equal, and it will perform them in the order given, there's really no reason to use the paren's anyway. You do not get different results between the using paren's or not do you. That, I would see as a problem.

  • When I save the Computed Formula - I get this message:

    Warnings were encountered during the pre-save validation process, and may result in a failure during save. Do you want to continue attempting to save?

    Then I choose 'Yes' and it saves fine and works as advertised. It works so I'm not complaining - just wondering why it warns me.

    Here's the actual warning:

    'BillyWillys' table

    - Error validating the formula for column 'MyComputedColumn'.

    The problem column seems to be a UDT column based on a Decimal type. If I change the column name in the formula to a static decimal number - the formula works fine and saves without warnings. However - if I change the COLUMN TYPE of the UDT column but leave the column name in the formula - the computed column STILL barks at me with warnings. Maybe it's just scared of UDT's in general. ~shrug~

  • I've run this scenario through several itterations on a test server, and come to the decision that since the computation doesn't happen till real time, it cannot pre-validate it. It's gonna warn you. I think it's like creating a proc that references a temp table. Until the temp table exists, it won't allow you to do it, but by creating the temp table, it can, and saves without the warning, and then performs as expected.

  • Thanks Scorpion...Thanks.

    I "Assume" such things are happening - but - I also assume the worst. Meaning - it's warning me for a real reason. Perhaps I'm doing something incorrectly or something will fail eventually. I'm a Microsoft guy but have been primarily a VB/ADO coder. I'm now using ASP and C# and forced to be somewhat of a DBA. SQL Server pales in comparison with most other Microsoft products as far as error messages and warnings are concerned. Gives me the willies 😉

    - B

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

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