USE [P21]
GO

/****** Object:  View [dbo].[msb_job_price_line_mac]    Script Date: 11/4/2024 10:41:38 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE view [dbo].[msb_job_price_line_mac]
as
select distinct a.job_no,a.job_price_hdr_uid,c.job_price_line_uid,c.inv_mast_uid,d.moving_average_cost,drv_job_src_loc.preferred_location_id
from job_price_hdr (NOLOCK) a
INNER JOIN job_price_line (NOLOCK) c ON (c.job_price_hdr_uid = a.job_price_hdr_uid)
INNER JOIN inv_loc (NOLOCK) d ON (d.inv_mast_uid = c.inv_mast_uid)
INNER JOIN (select job_price_hdr_uid,min(preferred_location_id) as 'preferred_location_id'
from job_price_customer_shipto (NOLOCK)
GROUP BY job_price_hdr_uid) as drv_job_src_loc ON (drv_job_src_loc.job_price_hdr_uid = a.job_price_hdr_uid)
AND (drv_job_src_loc.job_price_hdr_uid = c.job_price_hdr_uid)
AND (drv_job_src_loc.preferred_location_id = d.location_id)
group by a.job_no,a.job_price_hdr_uid,c.job_price_line_uid,c.inv_mast_uid,d.moving_average_cost,drv_job_src_loc.preferred_location_id
GO


