USE [Duplo_T]
GO
/****** Object: StoredProcedure [dbo].[FAN_TEST] Script Date: 08/13/2010 12:31:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[FAN_TEST]
@ORDER_NO CHAR(12)='', --default :空白(全て検索)
@TABLE_FLG CHAR(6)='1', --default :1 (T受注,T受注明細 )
@IN_OUT_BKN CHAR(2)='OD' -----default:OD (受注)
AS
PRINT '-- ============================================='
PRINT '-- 引数1:受注番号または仮受注番号'
PRINT '-- 引数2:テーブルの区分====以下詳細==========='
PRINT '-- 1 T受注 t_order と T受注明細 t_order_detail'
PRINT '-- 2 T仮受注 t_tmp_order と T仮受注明細 t_tmp_order_details'
PRINT '-- 3 M製品在庫 m_prod_stk と T製品入出庫 t_prod_in_out '
PRINT '-- 4 T出荷 t_ship'
PRINT '-- 5 T出荷明細機番t_ship_detail_mac'
PRINT '-- 6 T消耗品受払t_spl_receive_and_pay'
PRINT '-- 7 T売上t_sale'
PRINT '-- x M採番情報 m_auto_no'
PRINT '-- y T機番 t_mac'
PRINT '-- 引数3:製品入出庫区分:受注:OD 仮受注:TO 出荷番号:SJ'
--PRINT '-- 4 '
--PRINT '-- 7 '
--PRINT '-- 8 '
--PRINT '-- 9 '
--PRINT '-- a'
--PRINT '-- b'
--PRINT '-- c'
--PRINT '-- d'
--PRINT '-- e'
--PRINT '-- f'
--PRINT '-- g'
--PRINT '-- h'
--PRINT '-- i'
PRINT '-- ============================================='
PRINT '@ORDER_NO='+ @ORDER_NO
PRINT '@TABLE_FLG='+@TABLE_FLG
print SUBSTRING(@ORDER_NO,0,3)
print '@IN_OUT_BKN='+@IN_OUT_BKN
DECLARE @I INT
DECLARE @TEMP CHAR
DECLARE @prod_cd1 CHAR
DECLARE @prod_cd2 CHAR
DECLARE @whouse1 CHAR
DECLARE @whouse2 CHAR
Declare @payment_no CHAR(13)
SET @payment_no = @ORDER_NO
SET @I = 1
if @ORDER_NO IS NULL OR RTRIM(@ORDER_NO) <> ''
BEGIN
WHILE(@I <= LEN(@TABLE_FLG))
BEGIN
SET @TEMP = SUBSTRING(@TABLE_FLG,@I,1)
SET @I = @I + 1
IF @TEMP = '1'
BEGIN
SELECT *
FROM t_order
WHERE ORDER_NO = @ORDER_NO
order by ORDER_NO desc
SELECT *
FROM t_order_detail
WHERE ORDER_NO = @ORDER_NO
order by ORDER_NO desc, line
--SELECT *
--FROM t_order_detail_mac
--WHERE ORDER_NO = @ORDER_NO
--order by ORDER_NO desc, line
END
IF @TEMP = '2'
BEGIN
---------------T受注------------
IF SUBSTRING(@ORDER_NO,0,3) = 'OD'
BEGIN
select distinct t4.* from (select t1.* from t_tmp_order_details as t1 LEFT join t_order_detail as t2
on t1.line = t2.tmp_order_line and
t1.tmp_order_no = t2.tmp_order_no
where order_no=@ORDER_NO) as t3
left join t_tmp_order as t4
on t3.tmp_order_no = t4.tmp_order_no
select distinct t1.* from t_tmp_order_details as t1 LEFT join t_order_detail as t2
on t1.line = t2.tmp_order_line and
t1.tmp_order_no = t2.tmp_order_no
where order_no=@ORDER_NO
END
---------------T仮受注------------
IF SUBSTRING(@ORDER_NO,0,3) = 'TO'
BEGIN
SELECT *
FROM t_tmp_order
WHERE tmp_order_no = @ORDER_NO
order by tmp_order_no desc
SELECT *
FROM t_tmp_order_details
WHERE tmp_order_no = @ORDER_NO
order by tmp_order_no desc,line
END
END
IF @TEMP = '3'
BEGIN
---------------T受注------------
IF @IN_OUT_BKN = 'OD'
BEGIN
-- M製品在庫 m_prod_stk
select t2.* from
(select prod_cd1,prod_cd2,whouse1,whouse2 from t_order_detail
where order_no = @ORDER_NO
group by prod_cd1,prod_cd2,whouse1,whouse2) as t1
left join m_prod_stk as t2
on t1.prod_cd1 = t2.prod_cd1
and t1.prod_cd2 = t2.prod_cd2
and t1.whouse1 = t2.whouse1
and t1.whouse2 = t2.whouse2
WHERE 1=1
order by prod_cd1,prod_cd2,whouse1,whouse2
--T製品入出庫 t_prod_in_out
select t2.* from t_prod_in_out as t2
where 1=1 and
t2.slip_no = @ORDER_NO
order by t2.in_out_no desc,t2.line
END
IF @IN_OUT_BKN = 'TO'
BEGIN
---------------T仮受注------------
-- M製品在庫 m_prod_stk
select t2.* from
(select prod_cd1,prod_cd2,whouse1,whouse2 from t_tmp_order_details
where tmp_order_no = @ORDER_NO
group by prod_cd1,prod_cd2,whouse1,whouse2) as t1
left join m_prod_stk as t2
on t1.prod_cd1 = t2.prod_cd1
and t1.prod_cd2 = t2.prod_cd2
and t1.whouse1 = t2.whouse1
and t1.whouse2 = t2.whouse2
WHERE 1=1
order by prod_cd1,prod_cd2,whouse1,whouse2
--T製品入出庫 t_prod_in_out
select t2.* from t_prod_in_out as t2
where 1=1 and
t2.slip_no = @ORDER_NO
order by t2.in_out_no desc,t2.line
END
---------------T出荷------------
IF @IN_OUT_BKN = 'SJ'
BEGIN
-- M製品在庫 m_prod_stk
select t2.* from
(select prod_cd1,prod_cd2,whouse1,whouse2 from t_order_detail
where order_no = @ORDER_NO
group by prod_cd1,prod_cd2,whouse1,whouse2) as t1
left join m_prod_stk as t2
on t1.prod_cd1 = t2.prod_cd1
and t1.prod_cd2 = t2.prod_cd2
and t1.whouse1 = t2.whouse1
and t1.whouse2 = t2.whouse2
WHERE 1=1
order by prod_cd1,prod_cd2,whouse1,whouse2
--T製品入出庫 t_prod_in_out
select t2.* from t_prod_in_out as t2
where 1=1 and
t2.slip_no in
(
--T出荷 t_ship
select t1.ship_no from t_ship as t1
LEFT join(
SELECT *
FROM t_order_detail
) as t2
on t1.ship_no = t2.ship_no
WHERE t2.ORDER_NO = @ORDER_NO
)
order by t2.in_out_no desc,t2.line
END
END
IF @TEMP = '4'
BEGIN
--T出荷 t_ship
select t1.* from t_ship as t1
LEFT join(
SELECT *
FROM t_order_detail
) as t2
on t1.ship_no = t2.ship_no
and t1.order_line = t2.line
WHERE t2.ORDER_NO = @ORDER_NO
order by t1.ship_no desc, line
END
IF @TEMP = '5'
BEGIN
--T出荷明細機番 t_ship_detail_mac
select *
from t_ship_detail_mac
where ship_no in (
--T出荷 t_ship
select t1.ship_no from t_ship as t1
LEFT join(
SELECT *
FROM t_order_detail
) as t2
on t1.ship_no = t2.ship_no
and t1.order_line = t2.line
WHERE t2.ORDER_NO = @ORDER_NO)
order by ship_no desc, line
END
IF @TEMP = '6'
BEGIN
--T消耗品受払
select * from t_spl_receive_and_pay
where reference_slip_no =
(--T出荷 t_ship
select t1.ship_no from t_ship as t1
LEFT join(
SELECT *
FROM t_order_detail
) as t2
on t1.ship_no = t2.ship_no
and t1.order_line = t2.line
WHERE t2.ORDER_NO = @ORDER_NO)
order by acceptandpay_no desc
END
IF @TEMP = '7'
BEGIN
--T売上
select * from t_sale
where ship_no =
(--T出荷 t_ship
select t1.ship_no from t_ship as t1
LEFT join(
SELECT *
FROM t_order_detail
) as t2
on t1.ship_no = t2.ship_no
and t1.order_line = t2.line
WHERE t2.ORDER_NO = @ORDER_NO)
order by sale_no desc, sale_line
END
IF @TEMP = 'x'
BEGIN
-- M採番情報 m_auto_no
select * from m_auto_no
order by auto_kbn
END
IF @TEMP = 'y'
BEGIN
-- T機番
select * from t_mac where mac in (select mac from t_order_detail_mac where order_no=@ORDER_NO)
END
-- IF @TEMP = '4'
--BEGIN
----加工発注管理
-- SELECT *
-- FROM PROCESSHACCYUMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO
----加工発注明細
-- SELECT *
-- FROM PROCESSHACCYUDETAIL
-- WHERE PROCESSHACCYU_NO =
-- (SELECT PROCESSHACCYU_NO
-- FROM PROCESSHACCYUMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO)
--END
-- IF @TEMP = '5'
--BEGIN
-- --加工指示管理
-- SELECT *
-- FROM PROCESSINDICATEMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO
-- --加工指示明細
-- SELECT *
-- FROM PROCESSINDICATEDETAIL T1,(SELECT PROCESSINDICATE_NO
-- FROM PROCESSINDICATEMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO) T2
-- WHERE T1.PROCESSINDICATE_NO = T2.PROCESSINDICATE_NO
--END
-- IF @TEMP = '6'
--BEGIN
-- --積送管理
-- SELECT *
-- FROM SHIPMENTMNG
-- WHERE IN_ORDER_NO = @ORDER_NO
--END
-- IF @TEMP = '7'
--BEGIN
-- --付加情報管理
-- SELECT *
-- FROM ADDITIONMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO
----付加情報明細
-- SELECT *
-- FROM ADDITIONDETAIL T1, (SELECT ADDITION_NO
-- FROM ADDITIONMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO) T2
-- WHERE T1.ADDITION_NO = T2.ADDITION_NO
--END
-- IF @TEMP = '8'
--BEGIN
-- --製品在庫
-- SELECT *
-- FROM productStock
-- WHERE order_no = @ORDER_NO
----製品入出庫履歴
-- SELECT *
-- FROM productStockLog T1, ( SELECT product_stock_no
-- FROM productStock
-- WHERE order_no = @ORDER_NO) T2
-- WHERE T1.product_stock_no = T2.product_stock_no
--END
-- IF @TEMP = '9'
--BEGIN
-- --購買品在庫
-- SELECT *
-- FROM materialStock
---- WHERE order_no = @ORDER_NO
----購買品入出庫履歴
-- SELECT *
-- FROM materialStockLog T1, ( SELECT material_stock_no
-- FROM materialStock) T2
-- WHERE T1.material_stock_no = T2.material_stock_no
--END
-- IF @TEMP = 'a'
--BEGIN
-- --出荷指示管理shippingMng
-- SELECT *
-- FROM shippingMng
-- WHERE order_no = @ORDER_NO
----出荷指示明細shippingdetail
-- SELECT *
-- FROM shippingdetail T1, ( SELECT shipping_no
-- FROM shippingMng WHERE order_no = @ORDER_NO) T2
-- WHERE T1.shipping_no = T2.shipping_no
--END
-- IF @TEMP = 'b'
--BEGIN
-- --追加売上管理addsalesMng
-- SELECT *
-- FROM addsalesMng t1, ( SELECT tt1.shipping_no, tt1.shipping_seq
-- FROM shippingdetail tt1, (SELECT shipping_no
-- FROM shippingMng WHERE order_no =@ORDER_NO ) tt2
--where tt1.shipping_no = tt2.shipping_no
--) t2
-- WHERE t1.shipping_no = t2.shipping_no
-- and t1.shipping_seq = t2.shipping_seq
----追加売上明細addsalesDetail
-- SELECT *
-- FROM addsalesDetail T1, ( SELECT addsales_no
-- FROM addsalesMng t1, ( SELECT tt1.shipping_no, tt1.shipping_seq
-- FROM shippingdetail tt1, (SELECT shipping_no
-- FROM shippingMng WHERE order_no =@ORDER_NO ) tt2
--where tt1.shipping_no = tt2.shipping_no
--) t2
-- WHERE t1.shipping_no = t2.shipping_no
-- and t1.shipping_seq = t2.shipping_seq) T2
-- WHERE T1.addsales_no = T2.addsales_no
--END
-- IF @TEMP = 'c'
--BEGIN
-- --出荷実績管理ship_resultMng
--select * from ship_resultMng t1,
--(
-- SELECT t1.shipping_no, t1.shipping_seq
-- FROM shippingdetail T1, ( SELECT shipping_no
-- FROM shippingMng WHERE order_no = @ORDER_NO) T2
-- WHERE T1.shipping_no = T2.shipping_no) t2
--where t1.shipping_no = t2.shipping_no
--and t1.shipping_seq=t2.shipping_seq
----出荷実績明細ship_resultdetail
--select * from ship_resultdetail t1,
--(select t1.shipping_result_no from ship_resultMng t1,
--(
-- SELECT t1.shipping_no, t1.shipping_seq
-- FROM shippingdetail T1, ( SELECT shipping_no
-- FROM shippingMng WHERE order_no = @ORDER_NO) T2
-- WHERE T1.shipping_no = T2.shipping_no) t2
--where t1.shipping_no = t2.shipping_no
--and t1.shipping_seq=t2.shipping_seq) t2
--where
--t1.shipping_result_no = t2.shipping_result_no
--END
--IF @TEMP = 'd'
--BEGIN
-- --売上管理SalesMng
--select * from SalesMng t1,
--(
-- SELECT t1.shipping_no, t1.shipping_seq
-- FROM shippingdetail T1, ( SELECT shipping_no
-- FROM shippingMng WHERE order_no = @ORDER_NO) T2
-- WHERE T1.shipping_no = T2.shipping_no) t2
--where t1.shipping_no = t2.shipping_no
--and t1.shipping_seq=t2.shipping_seq
----売上明細SalesDetail
--select * from Salesdetail t1,
--(
--select t1.sales_no from SalesMng t1,
--(
-- SELECT t1.shipping_no, t1.shipping_seq
-- FROM shippingdetail T1, ( SELECT shipping_no
-- FROM shippingMng WHERE order_no = @ORDER_NO) T2
-- WHERE T1.shipping_no = T2.shipping_no) t2
--where t1.shipping_no = t2.shipping_no
--and t1.shipping_seq=t2.shipping_seq
--) t2
--where
--t1.sales_no = t2.sales_no
--END
--IF @TEMP = 'e'
--BEGIN
----入金管理paymentMng
--select * from paymentMng where payment_no = @payment_no
----入金明細paymentDetail
--select * from paymentDetail
--where payment_no = @payment_no
----受取手形billReceivable
--select * from billReceivable t3,
--(
--select payment_no,payment_seq from paymentDetail
--where payment_no = @payment_no
--)t4
--where t3.payment_no = t4.payment_no
--and t3.payment_seq = t4.payment_seq
--END
--IF @TEMP = 'f'
--BEGIN
----作業実績管理mn_resultMng
--select * from mn_resultMng t1, (
-- SELECT t1.addition_no,t1.addition_seq
-- FROM ADDITIONDETAIL T1, (SELECT ADDITION_NO
-- FROM ADDITIONMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO) T2
-- WHERE T1.ADDITION_NO = T2.ADDITION_NO
--) t2
--where
--t1.addition_no = t2.addition_no and
--t1.addition_seq = t2.addition_seq
----作業実績明細mn_resultdetail
--select * from mn_resultdetail t3,(
--select t1.result_no,t2.addition_no,t2.addition_seq from mn_resultMng t1, (
-- SELECT t1.addition_no,t1.addition_seq
-- FROM ADDITIONDETAIL T1, (SELECT ADDITION_NO
-- FROM ADDITIONMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO) T2
-- WHERE T1.ADDITION_NO = T2.ADDITION_NO
--) t2
--where
--t1.addition_no = t2.addition_no and
--t1.addition_seq = t2.addition_seq
--) t4
--where t3.result_no = t4.result_no
--END
--IF @TEMP = 'g'
--BEGIN
----半製品在庫halfproductStock
--select * from halfproductStock t1,(
--select result_no from mn_resultMng t1, (
-- SELECT t1.addition_no,t1.addition_seq
-- FROM ADDITIONDETAIL T1, (SELECT ADDITION_NO
-- FROM ADDITIONMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO) T2
-- WHERE T1.ADDITION_NO = T2.ADDITION_NO
--) t2
--where
--t1.addition_no = t2.addition_no and
--t1.addition_seq = t2.addition_seq
--) t2
--where
--t1.result_no = t2.result_no
----半製品入出庫履歴halfproductStockLog
--select * from halfproductStockLog t3,
--(
--select result_no from mn_resultMng t1, (
-- SELECT t1.addition_no,t1.addition_seq
-- FROM ADDITIONDETAIL T1, (SELECT ADDITION_NO
-- FROM ADDITIONMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO) T2
-- WHERE T1.ADDITION_NO = T2.ADDITION_NO
--) t2
--where
--t1.addition_no = t2.addition_no and
--t1.addition_seq = t2.addition_seq
--) t4
--where
--t3.result_no = t4.result_no
--END
--IF @TEMP = 'h'
--BEGIN
----作業投入管理mn_resultthrowinitemMng
--select * from mn_resultthrowinitemMng t1,(
--select t3.result_no, t3.result_seq from mn_resultdetail t3,(
--select t1.result_no,t2.addition_no,t2.addition_seq from mn_resultMng t1, (
-- SELECT t1.addition_no,t1.addition_seq
-- FROM ADDITIONDETAIL T1, (SELECT ADDITION_NO
-- FROM ADDITIONMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO) T2
-- WHERE T1.ADDITION_NO = T2.ADDITION_NO
--) t2
--where
--t1.addition_no = t2.addition_no and
--t1.addition_seq = t2.addition_seq
--) t4
--where t3.result_no = t4.result_no
--) t2
--where t1.result_no = t2.result_no
--and t1.result_seq = t2.result_seq
----作業投入明細mn_resultthrowinitemdetail
--select * from mn_resultthrowinitemdetail t3,
--(
--select resultthrowin_no from mn_resultthrowinitemMng t1,(
--select t3.result_no, t3.result_seq from mn_resultdetail t3,(
--select t1.result_no,t2.addition_no,t2.addition_seq from mn_resultMng t1, (
-- SELECT t1.addition_no,t1.addition_seq
-- FROM ADDITIONDETAIL T1, (SELECT ADDITION_NO
-- FROM ADDITIONMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO) T2
-- WHERE T1.ADDITION_NO = T2.ADDITION_NO
--) t2
--where
--t1.addition_no = t2.addition_no and
--t1.addition_seq = t2.addition_seq
--) t4
--where t3.result_no = t4.result_no
--) t2
--where t1.result_no = t2.result_no
--and t1.result_seq = t2.result_seq
--) t4
--where
--t3.resultthrowin_no = t4.resultthrowin_no
--END
--IF @TEMP = 'i'
--BEGIN
----投入品管理throwinitemMng
--select * from throwinitemMng t1, (
-- SELECT t1.addition_no,t1.addition_seq
-- FROM ADDITIONDETAIL T1, (SELECT ADDITION_NO
-- FROM ADDITIONMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO) T2
-- WHERE T1.ADDITION_NO = T2.ADDITION_NO
--) t2
--where t1.addition_no = t2.addition_no
--and t1.addition_seq = t2.addition_seq
----投入品明細明細throwinitemDetail
--select * from throwinitemDetail t3,(
--select throwinitem_no from throwinitemMng t1, (
-- SELECT t1.addition_no,t1.addition_seq
-- FROM ADDITIONDETAIL T1, (SELECT ADDITION_NO
-- FROM ADDITIONMNG
-- WHERE REFERENCE_ORDER_NO = @ORDER_NO) T2
-- WHERE T1.ADDITION_NO = T2.ADDITION_NO
--) t2
--where t1.addition_no = t2.addition_no
--and t1.addition_seq = t2.addition_seq
--) t4
--where t3.throwinitem_no = t4.throwinitem_no
--END
END
END
ELSE
BEGIN
WHILE(@I <= LEN(@TABLE_FLG))
BEGIN
SET @TEMP = SUBSTRING(@TABLE_FLG,@I,1)
SET @I = @I + 1
IF @TEMP = '1'
BEGIN
SELECT *
FROM t_order
order by order_no desc
SELECT *
FROM t_order_detail
order by order_no desc,line
--SELECT * FROM t_order_detail_mac order by order_no,line,mac_seq
END
IF @TEMP = '2'
BEGIN
SELECT *
FROM t_tmp_order
order by tmp_order_no desc
SELECT *
FROM t_tmp_order_details
order by tmp_order_no desc,line
END
IF @TEMP = '3'
BEGIN
-- M製品在庫 m_prod_stk
select * from m_prod_stk
WHERE 1=1
order by prod_cd1,prod_cd2,whouse1,whouse2
--T製品入出庫 t_prod_in_out
select * from t_prod_in_out
WHERE 1=1
order by in_out_no desc,line
END
IF @TEMP = '4'
BEGIN
--T出荷 t_ship
select t1.* from t_ship as t1
order by t1.ship_no desc, line
END
IF @TEMP = '5'
BEGIN
--T出荷明細機番 t_ship_detail_mac
select *
from t_ship_detail_mac
order by ship_no desc, line
END
IF @TEMP = '6'
BEGIN
--T消耗品受払
select *
from t_spl_receive_and_pay
END
IF @TEMP = '7'
BEGIN
--T売上
select *
from t_sale
order by sale_no desc, sale_line
END
IF @TEMP = 'x'
BEGIN
-- M採番情報 m_auto_no
select * from m_auto_no
order by auto_kbn
END
IF @TEMP = 'y'
BEGIN
-- T機番
select * from t_mac order by mac ,model_cd1, model_cd2
END
END
END