Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- CASE
- WHEN
- inv_pos_sum.cWhCode IN ( '01' ) THEN
- replace( inv_pos_sum.cInvCode, 'M-', '' ) ELSE inv_pos_sum.cInvCode
- END cInvCode,
- inv_pos_sum.cBatch,
- inv_pos_sum.cWhCode,
- inv_pos_sum.cPosCode,
- inv_pos_sum.cFree1,
- inv_pos_sum.iQuantity,
- ( CASE WHEN rd01_summary.iSOsID IS NULL THEN so_d.iSOsID ELSE rd01_summary.iSOsID END ) AS isosid,
- ( CASE WHEN rd01_summary.iSOsID IS NULL THEN so_d.cSCloser ELSE rd01_summary.cSCloser END ) AS closer
- FROM
- InvPositionSum inv_pos_sum
- LEFT JOIN Inventory inv ON inv_pos_sum.cInvCode = inv.cInvCode
- left JOIN (
- SELECT
- row_number ( ) OVER ( partition BY rd01_d.cInvCode, rd01_d.cBatch ORDER BY so_d.iSOsID ASC ) r,
- rd01_d.cInvCode,
- rd01_d.cBatch,
- so_d.cFree1,
- so_d.cSCloser,
- so_d.iSOsID,
- rd01_m.dnverifytime
- FROM
- rdrecords01 rd01_d
- LEFT JOIN SO_SODetails so_d ON rd01_d.iorderdid = so_d.iSOsID
- LEFT JOIN SO_SOMain so_m ON so_d.ID = so_m.ID
- left join rdrecord01 rd01_m
- on rd01_m.ID = rd01_d.ID
- ) rd01_summary ON inv_pos_sum.cInvCode = rd01_summary.cInvCode
- AND inv_pos_sum.cBatch = rd01_summary.cBatch
- AND rd01_summary.r= 1
- LEFT JOIN rdrecords10 rd10_d ON inv_pos_sum.cInvCode = rd10_d.cInvCode
- AND inv_pos_sum.cBatch = rd10_d.cBatch
- AND inv_pos_sum.cFree1 = rd10_d.cFree1
- LEFT JOIN SO_SODetails so_d ON rd10_d.iorderdid = so_d.iSOsID
- WHERE
- inv_pos_sum.iQuantity > 0
- AND inv_pos_sum.cFree1 != ''
- --AND inv.cInvCCode NOT IN ( '$cato_brand_code' )
- AND inv_pos_sum.cWhCode IN ( '01', '03', '06', '12' )
- and not (rd01_summary.cInvCode is not null and rd01_summary.dnverifytime is null)
- -- and inv_pos_sum.cinvcode='T-D289520'
- --AND NOT ( rd01_summary.iSOsID IS NOT NULL AND rd01_summary.cSCloser IS NULL AND inv_pos_sum.cFree1 = rd01_summary.cFree1 )
- --AND NOT ( so_d.iSOsID IS NOT NULL AND so_d.cSCloser IS NULL )
- ORDER BY
- ( CASE WHEN rd01_summary.iSOsID IS NULL THEN so_d.iSOsID ELSE rd01_summary.iSOsID END ) DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement