Categories
Database Development

Is it bad practice to calculate within the insert query?

I am trying to do a web application for time sheets.

I have three options to calculate the value of hours (AFAIK):

  1. In the form
  2. In the backend
  3. In the query

Is it smart or bad practice to do this calculation in the SQL query?

with list as (select code_id,code_ppu from code)

insert into hr values
(default,'JD','20-0001','PM','testing',1.25,
(select code_ppu from list where code_id='PM'),
(select 1.25 * code_ppu from list where code_id='PM')),
 
(default,'JD','20-0001','COPY','testing',2.25,
(select code_ppu from list where code_id='COPY'),
(select 2.25 * code_ppu from list where code_id='COPY'));

db fiddle https://www.db-fiddle.com/f/f8nZn5LQfbmKxAdxX2fdej/50

Leave a Reply

Your email address will not be published. Required fields are marked *