Results 1 to 3 of 3

Thread: Column Persisted Problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    240

    Column Persisted Problem

    Hi Guys,

    Is this possible?

    Code:
    Table1:
    Description     Quantity
    Item 1           10
    
    Table2:
    Description     Amount
    Item A           20
    
    Persisted:
    
    CREATE TABLE Table1
    (
       DescriptionID INT IDENTITY (1,1),
       Description VARCHAR(255),
       Quantity DECIMAL(18,2)
    )
    
    CREATE TABLE Table2
    (
       DescriptionID INT IDENTITY(1,1),
       Description VARCHAR(255),
       Amount DECIMAL(18,2),
       Total AS (Table1.Quantity * Amount) PERSISTED
    )
    Thanks in advance.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Column Persisted Problem

    What does the line

    Code:
    Total AS (Table1.Quantity * Amount) PERSISTED
    supposed to do? I can see that it is trying to multiply the value of Table1.Quantity with the value of Amount but when you are designing it manually where are you setting such PERSISTED information?

    And what database is this?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Column Persisted Problem

    The expression of a computed column can only inlcude other columns within the same table. The expression can be the result of a scalar udf function and can be persisted if the udf is considered deterministic (always returns the same result with the same parameters).

    So you can do what you want by using a udf, although based on what you posted it seems like a ridiculous method to use. Describe the business problem you are trying to solve and maybe we can offer some alternatives.

Posting Permissions

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



Click Here to Expand Forum to Full Width