码迷,mamicode.com
首页 > 其他好文 > 详细

存储过程返回表

时间:2019-09-10 13:33:11      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:har   exec   where   ble   HERE   RoCE   tac   create   nbsp   

ALTER PROCEDURE proc_xsddgz_lj
AS
--声明变量
--销售订单
BEGIN
DECLARE @fbillno NVARCHAR(255)
DECLARE @ddfentryid INT
DECLARE @fhdfentryid INT
CREATE TABLE #t(DDID INT,FHDID INT ,CKDID INT,ZGYSDID INT,CWYSDID INT)
CREATE TABLE #tt(DDID INT,FHDID INT ,CKDID INT,ZGYSDID INT,CWYSDID INT)
CREATE TABLE #ttt(DDID INT,FHDID INT ,CKDID INT,ZGYSDID INT,CWYSDID INT)
CREATE TABLE #tttt(DDID INT,FHDID INT ,CKDID INT,ZGYSDID INT,CWYSDID INT)
DECLARE @t TABLE(DDID INT,FHDID INT ,CKDID INT,ZGYSDID INT,CWYSDID INT)

--DECLARE @proc_xsddgz_lj TABLE(
--DDID INT,FHDID INT ,CKDID INT,ZGYSDID INT,CWYSDID INT
--)
SET @fbillno = ‘RA181274390‘
INSERT INTO #t(DDID)SELECT soe.FENTRYID
FROM T_SAL_ORDER so
INNER JOIN dbo.T_SAL_ORDERENTRY soe ON so.FID = soe.FID
WHERE so.FBILLNO = @fbillno

--SELECT *FROM #t
--drop TABLE #t
--DROP TABLE #tt
--发货单
INSERT INTO #tt(DDID,FHDID)
SELECT t.DDID,fhd.FENTRYID FROM #t t LEFT JOIN
(
SELECT sde.FENTRYID,sdel.FSID FROM dbo.T_SAL_DELIVERYNOTICEENTRY sde
INNER JOIN T_SAL_DELIVERYNOTICEENTRY_lk sdel ON sde.FENTRYID = sdel.FENTRYID
INNER JOIN T_SAL_DELIVERYNOTICE sd ON sd.fid = sde.FID
WHERE sd.FDOCUMENTSTATUS=‘C‘ )fhd ON t.DDID = fhd.FSID

TRUNCATE TABLE #t
INSERT INTO #t SELECT *FROM #tt
TRUNCATE TABLE #tt


--出库单
INSERT INTO #tt (DDID,FHDID,CKDID)
SELECT t.DDID,t.FHDID,ck.FENTRYID FROM #t t LEFT JOIN (
SELECT soe.FENTRYID,soel.FSID,soe.FACTQTY FROM dbo.T_SAL_OUTSTOCKENTRY soe
INNER JOIN dbo.T_SAL_OUTSTOCKENTRY_LK soel ON soe.FENTRYID = soel.FENTRYID
INNER JOIN T_SAL_OUTSTOCK so ON so.FID = soe.FID
WHERE so.FDOCUMENTSTATUS = ‘C‘) ck ON ck.FSID =t.FHDID


TRUNCATE TABLE #t
INSERT INTO #t SELECT *FROM #tt
TRUNCATE TABLE #tt


--暂估应收
INSERT INTO #ttt (DDID,FHDID,CKDID,ZGYSDID)
SELECT t.DDID,t.FHDID,t.CKDID ,zgys.FENTRYID FROM #t t LEFT JOIN (
SELECT ree.FENTRYID,relk.FSID,ree.FPRICEQTY FROM dbo.T_AR_RECEIVABLE re
INNER JOIN dbo.T_AR_RECEIVABLEENTRY ree ON re.FID = ree.FID
INNER JOIN dbo.T_AR_RECEIVABLEENTRY_LK relk ON ree.FENTRYID = relk.FENTRYID
WHERE re.FSETACCOUNTTYPE=2 AND re.FDOCUMENTSTATUS = ‘C‘)
zgys ON zgys.FSID = t.CKDID


TRUNCATE TABLE #t
INSERT INTO #t SELECT *FROM #ttt
TRUNCATE TABLE #ttt

--财务应收
INSERT INTO #tttt (DDID,FHDID,CKDID,ZGYSDID,CWYSDID)
SELECT t.DDID,t.FHDID,t.CKDID ,t.ZGYSDID,cwys.FENTRYID FROM #t t LEFT JOIN (
SELECT ree.FENTRYID,relk.FSID,ree.FPRICEQTY,re.FSETACCOUNTTYPE FROM dbo.T_AR_RECEIVABLE re
INNER JOIN dbo.T_AR_RECEIVABLEENTRY ree ON re.FID = ree.FID
INNER JOIN dbo.T_AR_RECEIVABLEENTRY_LK relk ON ree.FENTRYID = relk.FENTRYID
WHERE re.FSETACCOUNTTYPE=3 AND re.FDOCUMENTSTATUS = ‘C‘)
cwys ON cwys.FSID = t.ZGYSDID


TRUNCATE TABLE #t
INSERT INTO #t SELECT *FROM #tttt
TRUNCATE TABLE #tttt

INSERT INTO @t ( DDID, FHDID, CKDID, ZGYSDID, CWYSDID )SELECT *FROM #t

DROP TABLE #t
DROP TABLE #tt
DROP TABLE #ttt
DROP TABLE #tttt
SELECT *FROM @t
end

-----------------------------------------

declare @table table(DDID INT,FHDID INT ,CKDID INT,ZGYSDID INT,CWYSDID INT)--定义表变量来存放存储过程返回的内容
insert into @table EXEC proc_xsddgz_lj --将存储过程执行的结果放入表变量中
select *from @table

 

 

 

--------------------------------------

直接   EXEC proc_xsddgz_lj 也可以

存储过程返回表

标签:har   exec   where   ble   HERE   RoCE   tac   create   nbsp   

原文地址:https://www.cnblogs.com/RogerLu/p/11496720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!