SELECT nxmatid_s, nxmatid, nxsheetid_s, nxsheetid FROM nxsheet WHERE (nxsheet.nxname='Nestings\0\12');
SELECT nxsheetpathid_s, nxsheetpathid FROM nxsheetpath WHERE (nxsheetpath.nxsheetid='72');
SELECT nxorderposid, nxorderposid_s, nxspdmachtime, nxdetailcount, nxusedarea,nxarea, nxweight FROM nxsheetpathdet WHERE (nxsheetpathdet.nxsheetpathid=13);
SELECT nxorderposid, nxorderposid_s, nxcustmark FROM nxorderpos WHERE nxorderpos.nxorderposid IN (18, 20);
SELECT nxquality, nxthickness FROM nxmat WHERE (nxmat.nxmatid=6);


SELECT nxmatid FROM nxsheet WHERE (nxsheet.nxname='Nestings\0\11');
SELECT nxsheetpathid FROM nxsheetpath WHERE (nxsheetpath.nxsheetid='34');
SELECT nxorderposid,nxspdmachtime,nxdetailcount,nxusedarea,nxarea,nxweight FROM nxsheetpathdet WHERE (nxsheetpathdet.nxsheetpathid=2);
SELECT nxorderposid,nxcustmark FROM nxorderpos WHERE nxorderpos.nxorderposid IN (3);
SELECT nxquality FROM nxmat WHERE (nxmat.nxmatid=12);
SELECT nxthickness FROM nxmat WHERE (nxmat.nxmatid=12);

DROP VIEW MANUFACTURING;
CREATE VIEW MANUFACTURING AS
	SELECT	MMNN_MMOO_00000100.MnORef AS Reference, DIS_NEST_NEST_00000100.NstRef AS NstRef, MMNN_MMOO_00000100.PrdRef AS PrdRef, MMNN_MMOO_00000100.PrdName AS PrdName, MMNN_MMOO_00000100.CusRef AS Customer, MMNN_MMOO_00000100.OrdRef AS SaleOrder, MMNN_MMOO_00000100.Quantity AS Quantity, MMNN_MMOO_00000100.DDate AS DeliveryDate, MMNN_MMOO_00000300.WrkRef AS WorkCenter, MMNN_MMOO_00000300.OprRef AS Operation, PPRR_PPRR_00000100.DIS_Thickness AS Thickness, PPRR_PPRR_00000100.DIS_MatRef AS MatRef, PPRR_PPRR_00000100.DIS_UData1_Prt AS Udata1, PPRR_PPRR_00000100.DIS_UData2_Prt AS Udata2, PPRR_PPRR_00000100.DIS_UData8_Prt AS Udata8
	FROM	MMNN_MMOO_00000100, MMNN_MMOO_00000300, PPRR_PPRR_00000100, DIS_NEST_NEST_00000100
	WHERE	MMNN_MMOO_00000100.MnoRoot = MMNN_MMOO_00000300.MnoRef AND MMNN_MMOO_00000100.PrdRef = PPRR_PPRR_00000100.PrdRef;

DROP VIEW SHEET;
CREATE VIEW SHEET AS
	SELECT	PPRR_PPRR_00000100.recId AS recId, PPRR_PPRR_00000100.PrdRef AS PrdRef, PPRR_PPRR_00000100.PrdName AS PrdName, PPRR_PPRR_00000100.DIS_MatRef AS Material, PPRR_PPRR_00000100.DIS_CamQuan AS CAMQuantity, PPRR_PPRR_00000100.DIS_Width AS Width, PPRR_PPRR_00000100.DIS_Length AS Height, PPRR_PPRR_00000100.DIS_Thickness AS Thickness, PPRR_PPRR_00000100.DIS_Area AS Area, CAST(FORMAT(PPRR_PPRR_00000100.LastDate,'yyyyMMhhmmss') AS numeric) AS LastDate
	FROM	PPRR_PPRR_00000100
	WHERE	PPRR_PPRR_00000100.DIS_PClass = 51;

DROP VIEW PRODUCT;
CREATE VIEW PRODUCT AS
	SELECT	PPRR_PPRR_00000100.PrdRef AS PrdfRef, PPRR_PPRR_00000100.PrdName AS PrdName, PPRR_PPRR_00000100.DIS_Thickness AS Thickness, PPRR_PPRR_00000100.DIS_MatRef AS MatRef, PPRR_PPRR_00000100.DIS_UData1_Prt AS Udata1, PPRR_PPRR_00000100.DIS_UData2_Prt AS Udata2, PPRR_PPRR_00000100.DIS_UData8_Prt AS Udata8
	FROM	PPRR_PPRR_00000100

DROP VIEW PRODUCT_OPERATION;
CREATE VIEW PRODUCT_OPERATION AS
	SELECT	MMNN_MMOO_00000300.recId AS recId, MMNN_MMOO_00000300.MnORef AS ProductionOrder, MMNN_MMOO_00000300.PrdRef AS PrdRef, MMNN_MMOO_00000300.WrkRef AS WorkCenter, MMNN_MMOO_00000300.OprRef AS Operation, CAST(FORMAT(MMNN_MMOO_00000300.LastDate,'yyyyMMhhmmss') AS numeric) AS LastDate
	FROM	MMNN_MMOO_00000300


DROP VIEW nxorderpos;
CREATE VIEW nxorderpos AS
	SELECT DIS_NEST_NEST_00000100.recId AS nxmatid, DIS_NEST_NEST_00000100.MatRef AS nxmatid_s, MMNN_MMOO_00000300.recId AS nxorderposid, MMNN_MMOO_00000300.OrdRef AS nxorderposid_s, MMNN_MMOO_00000100.MnORef  AS nxcustmark, DIS_NEST_NEST_00000100.NstRef AS nxname, DIS_NEST_NEST_00000500.recId AS nxsheetpathid, DIS_NEST_NEST_00000500.PrdRefDst AS nxsheetpathid_s
	FROM	DIS_NEST_NEST_00000100, DIS_NEST_NEST_00000500, MMNN_MMOO_00000300, MMNN_MMOO_00000100
	WHERE	DIS_NEST_NEST_00000100.NstRef = DIS_NEST_NEST_00000500.NstRef AND
			DIS_NEST_NEST_00000500.MnORef = MMNN_MMOO_00000300.MnORef AND
			MMNN_MMOO_00000100.PrdRef = MMNN_MMOO_00000300.PrdRefDst;
	-- add: nxtimestamp, type: int

DROP VIEW nxmat;
CREATE VIEW nxmat AS
	SELECT	DIS_NEST_NEST_00000100.NstRef AS nxname, DIS_MMTT_MMTT_00000100.recId AS nxmatid, DIS_NEST_NEST_00000100.MatRef AS nxmatid_s, DIS_NEST_NEST_00000100.SThickness AS nxthickness, DIS_NEST_NEST_00000100.MatRef AS nxquality
	FROM	DIS_NEST_NEST_00000100, DIS_MMTT_MMTT_00000100
	WHERE	DIS_NEST_NEST_00000100.MatRef = DIS_MMTT_MMTT_00000100.MatRef;
	-- add: nxtimestamp, type: int

DROP VIEW nxsheet;
CREATE VIEW nxsheet AS
	SELECT	DIS_NEST_NEST_00000100.NstRef AS nxname, DIS_MMTT_MMTT_00000100.recId AS nxmatid, DIS_NEST_NEST_00000100.MatRef AS nxmatid_s, PPRR_PPRR_00000100.recId AS nxsheetid, DIS_NEST_NEST_00000100.ShtRef AS nxsheetid_s, CAST(FORMAT(DIS_NEST_NEST_00000100.LastDate,'yyyyMMhhmmss') AS numeric) AS nxtimestamp
	FROM	DIS_NEST_NEST_00000100, DIS_MMTT_MMTT_00000100, PPRR_PPRR_00000100
	WHERE	DIS_NEST_NEST_00000100.ShtRef = PPRR_PPRR_00000100.PrdRef and	DIS_NEST_NEST_00000100.MatRef = DIS_MMTT_MMTT_00000100.MatRef;

SELECT nxsheetpathid_s, nxsheetpathid, nxsheetid, nxsheetid_s FROM nxsheetpath WHERE (nxsheetpath.nxsheetid=72);
SELECT nxorderposid, nxorderposid_s, nxsheetpathid_s, nxsheetpathid, nxspdmachtime, nxdetailcount, nxusedarea, nxarea, nxweight FROM nxsheetpathdet WHERE (nxsheetpathdet.nxsheetpathid=72);

DROP VIEW nxsheetpath;
CREATE VIEW nxsheetpath AS
	SELECT	DIS_NEST_NEST_00000100.NstRef AS nxname, PPRR_PPRR_00000100.recId AS nxsheetpathid, DIS_NEST_NEST_00000100.ShtRef AS nxsheetpathid_s, PPRR_PPRR_00000100.recId AS nxsheetid, DIS_NEST_NEST_00000100.ShtRef AS nxsheetid_s
	FROM	DIS_NEST_NEST_00000100, PPRR_PPRR_00000100, DIS_NEST_NEST_00000500, MMNN_MMOO_00000300
	WHERE	DIS_NEST_NEST_00000100.ShtRef = PPRR_PPRR_00000100.PrdRef AND
			DIS_NEST_NEST_00000100.NstRef = DIS_NEST_NEST_00000500.NstRef AND
			DIS_NEST_NEST_00000500.MnORef = MMNN_MMOO_00000300.MnORef;

DROP VIEW nxsheetpathdet;
CREATE VIEW nxsheetpathdet AS
	SELECT	DIS_NEST_NEST_00000100.NstRef AS nxname, MMNN_MMOO_00000300.recId AS nxorderposid, MMNN_MMOO_00000300.MnORef AS nxorderposid_s, PPRR_PPRR_00000100.recId AS nxsheetpathid, DIS_NEST_NEST_00000100.ShtRef AS nxsheetpathid_s, MMNN_MMOO_00000300.DIS_NQ AS nxdetailcount, MMNN_MMOO_00000300.StdTime AS nxspdmachtime, PPRR_PPRR_00000100.DIS_Area AS nxarea, PPRR_PPRR_00000100.DIS_Area AS nxusedarea, PPRR_PPRR_00000100.Weight AS nxweight
	FROM	DIS_NEST_NEST_00000100, PPRR_PPRR_00000100, DIS_NEST_NEST_00000500, MMNN_MMOO_00000300
	WHERE	DIS_NEST_NEST_00000100.ShtRef = PPRR_PPRR_00000100.PrdRef AND
			DIS_NEST_NEST_00000100.NstRef = DIS_NEST_NEST_00000500.NstRef AND
			DIS_NEST_NEST_00000500.MnORef = MMNN_MMOO_00000300.MnORef;
	-- add: nxtimestamp, type: int

-- OLD:
CREATE VIEW nxsheetpath AS
	SELECT	DIS_NEST_NEST_00000100.NstRef AS nxname, DIS_NEST_NEST_00000500.recId AS nxsheetpathid, DIS_NEST_NEST_00000500.PrdRefDst AS nxsheetpathid_s, PPRR_PPRR_00000100.recId AS nxsheetid, DIS_NEST_NEST_00000100.ShtRef AS nxsheetid_s
	FROM	DIS_NEST_NEST_00000100, PPRR_PPRR_00000100, DIS_NEST_NEST_00000500, MMNN_MMOO_00000300
	WHERE	DIS_NEST_NEST_00000100.ShtRef = PPRR_PPRR_00000100.PrdRef AND
			DIS_NEST_NEST_00000100.NstRef = DIS_NEST_NEST_00000500.NstRef AND
			DIS_NEST_NEST_00000500.MnORef = MMNN_MMOO_00000300.MnORef;

CREATE VIEW nxsheetpathdet AS
	SELECT	DIS_NEST_NEST_00000100.NstRef AS nxname, MMNN_MMOO_00000300.recId AS nxorderposid, MMNN_MMOO_00000300.MnORef AS nxorderposid_s, DIS_NEST_NEST_00000500.recId AS nxsheetpathid, DIS_NEST_NEST_00000500.PrdRefDst AS nxsheetpathid_s, MMNN_MMOO_00000300.DIS_NQ AS nxdetailcount, MMNN_MMOO_00000300.StdTime AS nxspdmachtime, PPRR_PPRR_00000100.DIS_Area AS nxarea, PPRR_PPRR_00000100.DIS_Area AS nxusedarea, PPRR_PPRR_00000100.Weight AS nxweight
	FROM	DIS_NEST_NEST_00000100, PPRR_PPRR_00000100, DIS_NEST_NEST_00000500, MMNN_MMOO_00000300
	WHERE	MMNN_MMOO_00000300.PrdRefDst = PPRR_PPRR_00000100.PrdRef AND
			DIS_NEST_NEST_00000100.NstRef = DIS_NEST_NEST_00000500.NstRef AND
			DIS_NEST_NEST_00000500.MnORef = MMNN_MMOO_00000300.MnORef;
