SELECT
row = IDENTITY(8),
vrv_yn = CASE WHEN (SubString(prod_no, 1, 3) >= '251' AND SubString(prod_no, 1, 3) <= '254') OR (SubString(prod_no, 1, 3) = '258') THEN 'y' ELSE 'n' END,
seq_no = '',
apply_qty = 0,
order_qty = 0,
collect_amt = 0,
collect_amt1 = 0,
apply_price = 0, *
INTO #TB_TMP_WAY_E_PART
FROM
(
SELECT
part_no = a.part_no,
part_cname = a.part_cname,
prod_name = f.prod_name,
part_sno = IsNull(c.part_sno, ''),
useable_qty = CAST((c.assign_qty - c.use_qty) AS int),
deposit_real_qty = CAST(Sum(deposit_qty - sit_qty - snap_qty) AS int),
step_yn = a.step_yn,
award_yn = a.award_yn,
prod_no = a.prod_no
FROM baf006 AS a JOIN baf006b AS b ON a.part_no = b.part_no AND b.way_yy = '2022'
JOIN saf090s AS c ON b.part_sno = c.part_sno
LEFT JOIN saf280 AS d ON d.part_no = a.part_no AND d.cust_no = '26019' AND IsNull(d.cancel_date, '') = '' AND d.store_comp = '2' AND d.store_house = '12'
LEFT JOIN baf005 AS f ON f.prod_no = a.prod_no
WHERE ('' = 'RHF40VVLT' OR a.part_no LIKE 'RHF40VVLT%')
AND c.cust_no='26019' AND c.way_no='DA1021090001'
AND a.part_no NOT IN ('')
AND a.common_use_yn = 'Y'
AND (SubString(a.prod_no, 1, 3) < '251' OR SubString(a.prod_no, 1, 3) > '254') AND SubString(a.prod_no, 1, 3) != '258'
AND SubString(a.prod_no, 1, 3) != '116'
GROUP BY a.part_no, a.part_cname, a.prod_no, a.step_yn, a.award_yn, c.part_sno, c.assign_qty, c.use_qty, f.prod_name)
t1
WHERE (SubString(prod_no, 1, 3) < '251' OR SubString(prod_no, 1, 3) > '254') OR deposit_real_qty > 0 ORDER BY part_no
SELECT * FROM #TB_TMP_WAY_E_PART WHERE row > 0 * 100 AND row <= 0 * 100 + 100
沒有留言:
張貼留言