How can i calculate a formular was stored in sql ?
Hi, I have a table like this, i want to calculate a formular was stored in column TURNOVER_FORMULAR, The formular denpend on STK_CODE. How can i do it in SQL Server 2005 ?![alt text] : /storage/temp/3018-stk.png
You can use a computed column, but your formula is different on each line, and I don't know the exact rules. The formula to combine all of those variations will be a bit complicated, but it would probably be something like this. ALTER TABLE MyTable ADD turnover_formular AS CASE WHEN incoming_quantity > 1000 THEN total_freight * .5 + incoming_quantity * 1000 WHEN incoming_quantity BETWEEN 1 AND 1000 THEN total_freight * .5 + incoming_quantity * 5000 WHEN incoming_quantity = 0 AND outgoing_quantity > 0 THEN outgoing_weight * 1000 + outgoing_quantity * 500 ELSE total_freight * .45 END ;