sql server - SQL Query Add to total sum if.. else dont add -


how achieve result ? need calculate total cost of product when product made of components. new me, should add 100$ total cost if customer chooses service called delivery.

this have tried far.

select sum(component.cost*productcomponent.quantity) totcost productcomponent left join component on productcomponent.componentid = component.componentid  

i guess me total cost of product.

now there table service has many many relationship order. order has many many relationship service. need need add 100$ in total cost if there 'deliverly' used in service.

i have attached er diagram of database structure. hope question clear.

enter image description here

the basic idea you'd have put case statement in there add $100 if there record in service table given order. below query should of way there, looking @ cardinality of relationships may need group results or use subqueries chop down 1 row.

select case when sa.serviceid not null sum(component.cost*productcomponent.quantity) +    100     else sum(component.cost*productcomponent.quantity) end totcost  productcomponent pc left join component on productcomponent.componentid = component.componentid  join orderline o on o.productid = pc.productid join staffassignment sa on sa.saleid = o.saleid 

it looks multiple staffassignments give service 1 order that's might want use subquery select top 1 serviceid staffassignment saleid = o.saleid , serviceid not null

i don't have time test @ moment gives ideas solved.


Comments

Popular posts from this blog

android - Automated my builds -

how to proxy from https to http with lighttpd -

python - Flask migration error -