SELECT
h.unit_id as unitId,
h.site,
h.part_no as partNo,
h.part_desc as partDesc,
h.batch_no as batchNo,
h.location_id as locationId,
h.warehouse_id as warehouseId,
h.qty,
h.in_stock_flag as inStockFlag,
h.status,
h.status_db as statusDb,
h.created_date as createdDate,
h.created_by as createdBy,
h.modified_date as modifiedDate,
h.modified_by as modifiedBy,
h.print_count as printCount,
h.last_print_date as lastPrintDate,
h.printer_name as printerName,
h.qr_code as qrCode,
h.bar_code as barCode,
h.remark,
w.WareHouseName as warehouseName,
l.LocationName as locationName,
h.supplier_batch_no as supplierBatchNo,
h.supplier_manufacture_date as supplierManufactureDate,
h.height,h.wdr,h.eng_chg_level as engChgLevel,h.expired_date as expiredDate,
h.count_flag as countFlag,h.last_count_date as lastCountDate,h.source_type as sourceType
FROM handling_unit h WITH (NOLOCK)
LEFT JOIN warehouse w WITH (NOLOCK) ON h.warehouse_id = w.WareHouseID AND h.site = w.Site
LEFT JOIN location l WITH (NOLOCK) ON h.location_id = l.LocationID AND h.site = l.Site
AND h.site = #{params.site}
AND h.in_stock_flag = #{params.inStockFlag}
AND h.count_flag = #{params.countFlag}
AND h.part_no LIKE CONCAT('%', #{params.partNo}, '%')
AND h.batch_no LIKE CONCAT('%', #{params.batchNo}, '%')
AND h.location_id LIKE CONCAT('%', #{params.locationId}, '%')
AND h.unit_id LIKE CONCAT('%', #{params.unitId}, '%')
AND h.part_desc LIKE CONCAT('%', #{params.partDesc}, '%')
AND h.supplier_batch_no LIKE CONCAT('%', #{params.supplierBatchNo}, '%')
AND h.source_type = #{params.sourceType}
AND h.created_date >= #{params.startDate}
AND dateadd( DAY, 1, #{params.endDate} ) > h.created_date
ORDER BY h.created_date DESC
SELECT
h.unit_id AS unitId,
h.site,
h.part_no AS partNo,
h.part_desc AS partDesc,
h.batch_no AS batchNo,
h.location_id AS locationId,
h.warehouse_id AS warehouseId,
h.qty,
h.in_stock_flag AS inStockFlag,
h.status,
h.status_db AS statusDb,
h.created_date AS createdDate,
h.created_by AS createdBy,
h.modified_date AS modifiedDate,
h.modified_by AS modifiedBy,
h.print_count AS printCount,
h.last_print_date AS lastPrintDate,
h.printer_name AS printerName,
h.qr_code AS qrCode,
h.bar_code AS barCode,
p.remark,
w.WareHouseName AS warehouseName,
l.LocationName AS locationName,
p.pallet_id,
s.station_id,
s.station_area,
h.height,
b.position,
b.layer,
p.calling_flag,
p.wcs_location AS wcsLocation,
h.count_flag AS countFlag,
h.last_count_date AS lastCountDate,
h.eng_chg_level AS engChgLevel,
h.expired_date AS expiredDate,
h.receive_date AS receiveDate,
h.wdr
FROM handling_unit h
LEFT JOIN warehouse w ON h.warehouse_id = w.WareHouseID AND h.site = w.Site
LEFT JOIN location l ON h.location_id = l.LocationID AND h.site = l.Site
LEFT JOIN pallet_detail b ON h.unit_id = b.serial_no AND h.site = b.site
LEFT JOIN pallet p ON b.pallet_id = p.pallet_id AND b.site = p.site
LEFT JOIN agv_station s ON p.location_code = s.station_code
and p.pallet_id IS NOT NULL
AND h.site = #{params.site}
AND h.in_stock_flag = #{params.inStockFlag}
AND h.count_flag = #{params.countFlag}
AND h.part_no LIKE '%' + #{params.partNo} + '%'
AND h.batch_no LIKE '%' + #{params.batchNo} + '%'
AND h.location_id LIKE '%' + #{params.locationId} + '%'
AND h.unit_id LIKE '%' + #{params.unitId} + '%'
AND h.part_desc LIKE '%' + #{params.partDesc} + '%'
AND p.pallet_id LIKE '%' + #{params.palletId} + '%'
AND s.station_id LIKE '%' + #{params.stationId} + '%'
ORDER BY h.created_date DESC
SELECT
h.unit_id as unitId,
h.site,
h.part_no as partNo,
h.part_desc as partDesc,
h.batch_no as batchNo,
h.location_id as locationId,
h.warehouse_id as warehouseId,
h.qty,
h.in_stock_flag as inStockFlag,
h.status,
h.status_db as statusDb,
h.created_date as createdDate,
h.created_by as createdBy,
h.modified_date as modifiedDate,
h.modified_by as modifiedBy,
h.print_count as printCount,
h.last_print_date as lastPrintDate,
h.printer_name as printerName,
h.qr_code as qrCode,
h.bar_code as barCode,
h.remark,
w.WareHouseName as warehouseName,
l.LocationName as locationName,
p.pallet_id,
s.station_id,
s.station_area,
h.height,
h.last_count_date as lastCountDate
FROM handling_unit h WITH (NOLOCK)
LEFT JOIN warehouse w WITH (NOLOCK) ON h.warehouse_id = w.WareHouseID AND h.site = w.Site
LEFT JOIN location l WITH (NOLOCK) ON h.location_id = l.LocationID AND h.site = l.Site
left join pallet_detail b WITH (NOLOCK) on h.unit_id = b.serial_no and h.site=b.site
left join pallet p WITH (NOLOCK) on b.pallet_id = p.pallet_id and b.site = p.site
left join agv_station s WITH (NOLOCK) on p.location_code=s.station_code
AND h.site = #{params.site}
AND h.in_stock_flag = #{params.inStockFlag}
AND h.part_no LIKE CONCAT('%', #{params.partNo}, '%')
AND h.batch_no LIKE CONCAT('%', #{params.batchNo}, '%')
AND h.location_id LIKE CONCAT('%', #{params.locationId}, '%')
AND h.unit_id LIKE CONCAT('%', #{params.unitId}, '%')
AND h.part_desc LIKE CONCAT('%', #{params.partDesc}, '%')
AND h.part_desc LIKE CONCAT('%', #{params.partDesc}, '%')
AND p.pallet_id LIKE CONCAT('%', #{params.palletId}, '%')
AND s.station_id LIKE CONCAT('%', #{params.stationId}, '%')
ORDER BY h.created_date DESC
UPDATE handling_unit
SET in_stock_flag = 'N', epc = CONVERT(VARCHAR(8), GETDATE(), 112)
WHERE unit_id NOT IN (SELECT serial_no FROM pallet_detail)
AND in_stock_flag = 'Y'
AND site = #{site}
UPDATE handling_unit
SET in_stock_flag = 'Y', epc = ''
WHERE epc = CONVERT(VARCHAR(8), GETDATE(), 112)
AND in_stock_flag = 'N'
AND site = #{site}