Job description
I will order a SQL report for subiekt nexo containing:
1. Symbol
2. the inventory as of today
3. the date of the first delivery of a given symbol (PZ)
4. date of last delivery of a given symbol (PZ)
Below a similar report from GT:
select
'symbol' = t.tw_Symbol,
'name' = t.tw_Name,
'manufacturer' = k.adr_Name,
'card price' = isnull(c.tc_CenaNetto0,0),
'ost purchase price' = isnull(o.ost_price,0),
'state' = s.st_State,
'warehouse' = m.mag_Name
from
dbo.tw__Commodity t
left join dbo.vwCustomers k on (k.kh_id = t.tw_IdProducer)
inner join dbo.tw_State s on (s.st_TowId = t.tw_Id)
inner join dbo.sl_Magazine m on (s.st_MagId = m.mag_Id)
left join
(
select
mr_TowId,
mr_data,
mw_data,
ost_price
from
(
select
mr_TowId,
mr_data,
mr_id,
mw_data,
ost_price = isnull(b.mw_Cena,0),
rn = row_number() over (partition by mr_TowId order by mr_data desc, mr_id desc, mw_data desc)
from dbo.dok_magruch a
join dbo.dok_magwart b
on (a.mr_SeriesId = b.mw_SeriesId)
where (a.mr_Id = a.mr_seriesId)
) x
where (rn = 1)
) o on (t.tw_Id = o.mr_TowId)
left join dbo.tw_Cena c on (t.tw_Id = c.tc_IdTowId)
order by t.tw_symbol