Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Table Design help with 2 computed columns

Table Design help with 2 computed columns

Scheduled Pinned Locked Moved Database
helppythondatabasesql-serverdesign
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Simon_Whale
    wrote on last edited by
    #1

    Using SQL Server 2008 r2 I am trying to design a table, which has 2 computed column based on the product of other columns including a computed column, which SQL Server doesn't like.

    CREATE TABLE [dbo].[BaseRate2](
    [ProductType] [varchar](100) NOT NULL,
    [LinkToRate] [decimal](18, 0) NULL,
    [CopyOfRates] [decimal](18, 0) NULL,
    [BCdiscountLoading] [decimal](18, 0) NULL,
    [OtherLoading] [decimal](18, 0) NULL,
    [ClaimsLoading] [decimal](18, 0) NULL,
    [NoClaimsDiscount3Yr] [decimal](18, 0) NULL,
    [NoClaimsDiscount4Yr] [decimal](18, 0) NULL,
    [NoClaimsDiscount5Yr] [decimal](18, 0) NULL,
    [ConstructionLoading] [decimal](18, 0) NULL,
    [DiscretionaryDiscount] [decimal](18, 0) NULL,
    [MinPremiumLoading] [decimal](18, 0) NULL,
    [SecurityDiscount] [decimal](18, 0) NULL,
    [ProductLoading] AS ((((((([ClaimsLoading]*[NoClaimsDiscount3Yr])*[NoClaimsDiscount4Yr])*[NoClaimsDiscount5Yr])*[ConstructionLoading])*[DiscretionaryDiscount])*[MinPremiumLoading])*[SecurityDiscount])
    ) ON [PRIMARY]

    Now when I try to add the second computed column when uses the first computed column (ProductLoading) this is where SQL throws an error as it should do.

    RateUsed as ([CopyOfRates] * [BCdiscountLoading] * [OtherLoading] * [ProductLoading])

    Is there some other technique that I could design this table without manually calculating these product columns (ProductLoadings and RateUsed). Thanks Simon

    Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

    L M 2 Replies Last reply
    0
    • S Simon_Whale

      Using SQL Server 2008 r2 I am trying to design a table, which has 2 computed column based on the product of other columns including a computed column, which SQL Server doesn't like.

      CREATE TABLE [dbo].[BaseRate2](
      [ProductType] [varchar](100) NOT NULL,
      [LinkToRate] [decimal](18, 0) NULL,
      [CopyOfRates] [decimal](18, 0) NULL,
      [BCdiscountLoading] [decimal](18, 0) NULL,
      [OtherLoading] [decimal](18, 0) NULL,
      [ClaimsLoading] [decimal](18, 0) NULL,
      [NoClaimsDiscount3Yr] [decimal](18, 0) NULL,
      [NoClaimsDiscount4Yr] [decimal](18, 0) NULL,
      [NoClaimsDiscount5Yr] [decimal](18, 0) NULL,
      [ConstructionLoading] [decimal](18, 0) NULL,
      [DiscretionaryDiscount] [decimal](18, 0) NULL,
      [MinPremiumLoading] [decimal](18, 0) NULL,
      [SecurityDiscount] [decimal](18, 0) NULL,
      [ProductLoading] AS ((((((([ClaimsLoading]*[NoClaimsDiscount3Yr])*[NoClaimsDiscount4Yr])*[NoClaimsDiscount5Yr])*[ConstructionLoading])*[DiscretionaryDiscount])*[MinPremiumLoading])*[SecurityDiscount])
      ) ON [PRIMARY]

      Now when I try to add the second computed column when uses the first computed column (ProductLoading) this is where SQL throws an error as it should do.

      RateUsed as ([CopyOfRates] * [BCdiscountLoading] * [OtherLoading] * [ProductLoading])

      Is there some other technique that I could design this table without manually calculating these product columns (ProductLoadings and RateUsed). Thanks Simon

      Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      It blows, because you're using a value in your calculation that might not be available yet. Create the table, and a view - add the second computed field to the view. Alternatively, you could use a normal (non-calculated) field, and update it's contents using a trigger.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      S 1 Reply Last reply
      0
      • L Lost User

        It blows, because you're using a value in your calculation that might not be available yet. Create the table, and a view - add the second computed field to the view. Alternatively, you could use a normal (non-calculated) field, and update it's contents using a trigger.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        Eddy, Thanks for that suggestion (views) it worked, but I decided against the idea after following through on the documentation of the table / view as it made it more complex to maintain in this situation. So sadly I adopted the manual calculations before entering into the table. Thanks again :-D

        Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

        1 Reply Last reply
        0
        • S Simon_Whale

          Using SQL Server 2008 r2 I am trying to design a table, which has 2 computed column based on the product of other columns including a computed column, which SQL Server doesn't like.

          CREATE TABLE [dbo].[BaseRate2](
          [ProductType] [varchar](100) NOT NULL,
          [LinkToRate] [decimal](18, 0) NULL,
          [CopyOfRates] [decimal](18, 0) NULL,
          [BCdiscountLoading] [decimal](18, 0) NULL,
          [OtherLoading] [decimal](18, 0) NULL,
          [ClaimsLoading] [decimal](18, 0) NULL,
          [NoClaimsDiscount3Yr] [decimal](18, 0) NULL,
          [NoClaimsDiscount4Yr] [decimal](18, 0) NULL,
          [NoClaimsDiscount5Yr] [decimal](18, 0) NULL,
          [ConstructionLoading] [decimal](18, 0) NULL,
          [DiscretionaryDiscount] [decimal](18, 0) NULL,
          [MinPremiumLoading] [decimal](18, 0) NULL,
          [SecurityDiscount] [decimal](18, 0) NULL,
          [ProductLoading] AS ((((((([ClaimsLoading]*[NoClaimsDiscount3Yr])*[NoClaimsDiscount4Yr])*[NoClaimsDiscount5Yr])*[ConstructionLoading])*[DiscretionaryDiscount])*[MinPremiumLoading])*[SecurityDiscount])
          ) ON [PRIMARY]

          Now when I try to add the second computed column when uses the first computed column (ProductLoading) this is where SQL throws an error as it should do.

          RateUsed as ([CopyOfRates] * [BCdiscountLoading] * [OtherLoading] * [ProductLoading])

          Is there some other technique that I could design this table without manually calculating these product columns (ProductLoadings and RateUsed). Thanks Simon

          Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          As Eddie suggested the Product loading may not exists. This is not going to make you happy. You can replace [ProductLoading] in your second field with the ENTIRE formula from the first field. ducks and runs I told you it would not make you happy!

          Never underestimate the power of human stupidity RAH

          S 1 Reply Last reply
          0
          • M Mycroft Holmes

            As Eddie suggested the Product loading may not exists. This is not going to make you happy. You can replace [ProductLoading] in your second field with the ENTIRE formula from the first field. ducks and runs I told you it would not make you happy!

            Never underestimate the power of human stupidity RAH

            S Offline
            S Offline
            Simon_Whale
            wrote on last edited by
            #5

            I understood the why it isn't working and was trying to see if there was another way to do this computationally. while I did consider the approach you suggested, I also have to write detailed documentation around this insurance rating API and was looking for a easy / elegant solution that would make documentation easy and clear. With the documentation in mind I decided that it would be easier for me to explain the columns and how they are calculated manually. :(

            Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

            M 1 Reply Last reply
            0
            • S Simon_Whale

              I understood the why it isn't working and was trying to see if there was another way to do this computationally. while I did consider the approach you suggested, I also have to write detailed documentation around this insurance rating API and was looking for a easy / elegant solution that would make documentation easy and clear. With the documentation in mind I decided that it would be easier for me to explain the columns and how they are calculated manually. :(

              Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              Simon_Whale wrote:

              easy / elegant solution

              Does not describe the way sql works some times.

              Never underestimate the power of human stupidity RAH

              S 1 Reply Last reply
              0
              • M Mycroft Holmes

                Simon_Whale wrote:

                easy / elegant solution

                Does not describe the way sql works some times.

                Never underestimate the power of human stupidity RAH

                S Offline
                S Offline
                Simon_Whale
                wrote on last edited by
                #7

                Hence I came here to tap into the vast knowledge of others :D

                Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups