Skip to content
Advertisement

Create a column from 2 columns of 2 different tables

I have these 2 tables. What I want is that LineTotal is equal to Quantity*Price. I know that if I have Price in my OrderLine I could do LineTotal as ([quantity]*[price]). But that’s not what I want. I also read something about triggers but it wouldn’t work due to errors. What I tried

I use SQL Server 2018

Advertisement

Answer

Here is an example for a Trigger – however, this might fir the current requirement, but you should get familiar with further possibilities of SQL Triggers (such as handling inserts and updates differently in case quantity in OrderLine changes or even in case the price in Rewards changes):

Fiddle: http://sqlfiddle.com/#!18/0a4a9/1/4

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement