IF EXISTS(SELECT 1 FROM sys.views WHERE Name = 'quotes_vQuoteEnquiryItems')
DROP VIEW [dbo].[quotes_vQuoteEnquiryItems]
GO

CREATE VIEW [dbo].[quotes_vQuoteEnquiryItems]
AS
SELECT        
	enquiryItem.recId, 
	enquiryItem.itemID, 
	enquiryItem.isActive, 
	enquiryItem.surfaceId, 
	enquiryItem.ParentSurfaceItemId, 
    enquiryItem.QuoteEnquiryItems_QuoteEnquiryItems_PartNumber, 
	enquiryItem.QuoteEnquiryItems_QuoteEnquiryItems_Quantity, 
	enquiryItem.QuoteEnquiryItems_QuoteEnquiryItems_Sequence, 

	CreatedBy = item.createdBy, 
	CreatedByDisplay = createUser.userDisplay, 
	CreatedDate = item.dateCreated, 
	
    UpdatedBy = item.updatedBy, 
	UpdatedByDisplay = updateUser.userDisplay,
	UpdatedDate = item.dateUpdated
	
FROM
	dbo.quotes_vQuotes AS quote INNER JOIN
	dbo.publ_QuoteEnquiryItems AS enquiryItem ON quote.itemID = enquiryItem.ParentSurfaceItemId LEFT OUTER JOIN
	dbo.pal_SurfaceItem AS item ON enquiryItem.itemID = item.recId LEFT OUTER JOIN
	dbo.pal_vUserShared AS createUser ON item.createdBy = createUser.recId LEFT OUTER JOIN
	dbo.pal_vUserShared AS updateUser ON item.updatedBy = updateUser.recId
WHERE
	quote.isActive = 1
	AND enquiryItem.isActive = 1
	AND item.isDeleted = 0
GO


