USE [P21]
GO

/****** Object:  View [dbo].[mh_vw_last_po]    Script Date: 10/31/2024 4:43:56 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE view [dbo].[mh_vw_last_po] as

select * from (
select ph.supplier_id, s.supplier_name as ls_supplier_name,  item_id, order_date, row_number() over (partition by item_id order by order_date desc) as rw_nm

from p21_view_po_hdr ph
left outer join p21_view_po_line pl on ph.po_no = pl.po_no
left outer join p21_view_supplier s on  ph.supplier_id = s.supplier_id
where  isnull(ph.cancel_flag,'n') <> 'y'
and isnull(pl.cancel_flag, 'n') <> 'y'
and isnull(ph.delete_flag, 'n') <> 'y'
and isnull(pl.delete_flag, 'n') <> 'y') t1
where rw_nm = 1
GO

