select 
 dpt_ct.NAME									'CustName'
, sqt.QUOTATIONID + ' : ' + sqt.QUOTATIONNAME	'QuotationRef'
, sqt.PROJIDREF									'ProjIdRef'
, pt.NAME										'ProjName'
, cqj.PALSALESQUOTDOCREV						'QuotationRevision'
, dpt_hcw.NAME									'SalesTaker'
, sqlp.PALITEM									'PalItem'
, sqlp.ITEMID									'ItemId'
, sqlp.PROJDESCRIPTION							'Description'
, sqlp.SALESQTY									'SalesQty'
, sqlp.PALUNITSTDCOST							'UnitStdCost'
, (sqlp.PALFACTORK1/100)						'FactorK1'
, sqlp.PALFACTORK2								'FactorK2'
, (sqlp.PALSTDBUSINESSCONDITION/100)			'StdBusinessCondition'
, (sqlp.PALCUSTOMIZEDBUSINESSCONDITION/100)		'CustomizedBusinessCondition'
, (sqlp.PALFACTORK3/100)						'FactorK3'
, (sqlp.PALDISCOUNTPERCENT/100)					'DiscountPercent'
, sqlp.PALDLVREASONID							'DlvReasonId'
--, * 
from SALESQUOTATIONTABLE sqt

left outer join SALESQUOTATIONLINE sqlp
	on sqlp.QUOTATIONID = sqt.QUOTATIONID
	and sqlp.PALTYPEOFLINE = 0
	and sqlp.DATAAREAID = sqt.DATAAREAID
	and sqlp.PARTITION = sqt.PARTITION
	left outer join SALESQUOTATIONLINE sqlc
		on sqlc.QUOTATIONID = sqlp.QUOTATIONID
		and sqlc.PALPARENTCHILDREFRECID = sqlp.RECID
		and sqlc.PALTYPEOFLINE = 1
		and sqlc.DATAAREAID = sqlp.DATAAREAID
		and sqlc.PARTITION =  sqlp.PARTITION

join HCMWORKER hcw
	on hcw.RECID = sqt.WORKERSALESTAKER	
	and hcw.PARTITION = sqt.PARTITION
	join DIRPARTYTABLE dpt_hcw
		on dpt_hcw.RECID = hcw.PERSON
		and dpt_hcw.PARTITION = hcw.PARTITION

left outer join PROJTABLE pt
	on pt.PROJID = sqt.PROJIDREF
	and pt.DATAAREAID = sqt.DATAAREAID
	and pt.PARTITION = sqt.PARTITION

join CUSTTABLE ct
	on ct.ACCOUNTNUM = sqt.CUSTACCOUNT
	and ct.DATAAREAID = sqt.DATAAREAID
	and ct.PARTITION = sqt.PARTITION
	join DIRPARTYTABLE dpt_ct
		on dpt_ct.RECID = ct.PARTY
		and dpt_ct.PARTITION = ct.PARTITION
 
join CUSTQUOTATIONSALESLINK cqsl
	on cqsl.ORIGQUOTATIONID = sqt.QUOTATIONID
	and cqsl.DATAAREAID = sqt.DATAAREAID
	and cqsl.PARTITION = sqt.PARTITION
	join CUSTQUOTATIONJOUR cqj
		on cqj.SALESID = cqsl.SALESID
		and cqj.QUOTATIONID = cqsl.QUOTATIONID
		and cqj.QUOTATIONDATE = cqsl.QUOTATIONDATE
		and cqj.PARTITION = cqsl.PARTITION
 

where cqj.RECID = 5637550341
and sqt.DATAAREAID = 'PAL'
and sqt.PARTITION = 5637144576
and sqlp.PALTYPEOFLINE = 0
and sqlc.PALTYPEOFLINE = 1