Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.70 KB | None | 0 0
  1. select point_hash,
  2.               case when s1.parent_id != -1 then
  3.                 COALESCE((
  4.                     select raw_product_receipt.price_for_unit from receipt
  5.                         inner join raw_product_receipt on receipt_id=receipt.id
  6.                     where storehouse=(select name from storehouse as s2 where s2.id=s1.parent_id) and price_id=$1
  7.                          and price_for_unit<>0
  8.                         order by receipt.date desc
  9.                         limit 1
  10.                          ), 0)
  11.               else
  12.                 COALESCE((
  13.                     select raw_product_receipt.price_for_unit  from receipt
  14.                         inner join raw_product_receipt on receipt_id=receipt.id
  15.                         where storehouse=s1.name and price_id=$1 and price_for_unit<>0
  16.                     order by receipt.date desc
  17.                         limit 1
  18.                         ), 0)
  19.                         end
  20.             from storehouse as s1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement