sql - Create a view with datetime calculation?How? -



sql - Create a view with datetime calculation?How? -

i have tables receipt , rent. database rent auto company. in receipt table have total cost , in receipt table rental date , homecoming date. want create view 2 tables , within view funktion calculate , subtract 2 dates (return-rental) in hours, multiply number , set in total cost column. this: if hours>24 total cost = 24*8 else 24*10 - example. , result should go in total cost column. im sql beginner dont know how or if can done. code view (there more columns , it´s in german) of import ones rechnungsbetrag=total cost, ausleihdatum=rental date, ruckgabedatum=return date. appreciate help.

create view vrechnung select tbl_rechnung.rechnungsnr, tbl_rechnung.kunden_id, tbl_mieten.ausleihdatum, tbl_mieten.rückgabedatum, tbl_rechnung.rechnungsbetrag , tbl_sachbearbeiter.nachname sachbearbeiter tbl_rechnung bring together tbl_mieten on tbl_rechnung.kunden_id=tbl_mieten.kunden_id bring together tbl_sachbearbeiter on tbl_rechnung.svnr=tbl_sachbearbeiter.svnr

well hard-coded way be:

create view vrechnung select tbl_rechnung.rechnungsnr, tbl_rechnung.kunden_id, tbl_mieten.ausleihdatum, tbl_mieten.rückgabedatum, tbl_rechnung.rechnungsbetrag , tbl._mieten.rückgabedatum, tbl_sachbearbeiter.nachname sachbearbeiter, datediff(hour, rental, return) * case when datediff(hour, rental, return) > 24 8 else 10 end totalcost tbl_rechnung bring together tbl_mieten on tbl_rechnung.kunden_id=tbl_mieten.kunden_id bring together tbl_sachbearbeiter on tbl_rechnung.svnr=tbl_sachbearbeiter.svnr

(i don't know high german added english language words mentioned in query)

note i've added line breaks create sql much easier read.

a better way have table specifies rate given range of hours , bring together that, that's question :)

sql sql-server database tsql

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -