发几个sybase写过的存储过程
/*
--审计报告编制
*/
CREATE PROC P_S_GETMANALLUNIONREPORT_EDIT
(
@USERID VARCHAR(30)
)
AS
BEGIN
CREATE TABLE #T_MAN_REPORT
(
DOCID INT NULL,
ID INT NULL,
PLANYEAR INT NULL,
DOCMODELID INT NULL,
PLANID VARCHAR(40) NULL,
PROJECTNAME VARCHAR(200) NULL,
UNIONID VARCHAR(60) NULL,
ATTACHID VARCHAR(60) NULL,
USERID VARCHAR(30) NULL,
ACCEPTER VARCHAR(30) NULL,
RPTNAME VARCHAR(200) NULL,
SIGNNAME VARCHAR(50) NULL,
CREATETM DATETIME NULL,
STATEID INT NULL,
STATENAME VARCHAR(50) NULL,
INFO INT NULL,
INFONAME VARCHAR(50) NULL,
A_COUNT INT NULL,
OUSERID VARCHAR(30) NULL ,
GUID VARCHAR(40) NULL,
NEWGUID VARCHAR(40) NULL
)
INSERT INTO #T_MAN_REPORT(DOCID,ID,UNIONID,ATTACHID,USERID,ACCEPTER,INFO,STATEID,GUID,NEWGUID)
SELECT A.ID AS DOCID,B.ID AS TRANSMITID,B.UNIONID,B.ATTACHID AS NEWUNIONID,B.USERID AS SENDER,B.ACCEPTER,B.INFO AS DOCINFO,B.STATEID AS DOCSTATE,B.GUID,B.NEWGUID FROM T_B_AUDITREPORT AS A,T_B_REPORT_TRANSMIT AS B WHERE B.USERID=B.ACCEPTER AND INFO=4 AND B.ACCEPTER=@USERID AND B.STATEID =1 AND A.GUID=B.GUID
UPDATE #T_MAN_REPORT
SET #T_MAN_REPORT.DOCMODELID=B.DOCMODELID, #T_MAN_REPORT.PLANID=B.PLANID , #T_MAN_REPORT.RPTNAME=B.RPTNAME,#T_MAN_REPORT.CREATETM=B.CREATETM ,#T_MAN_REPORT.OUSERID =B.USERID
FROM #T_MAN_REPORT ,T_B_AUDITREPORT AS B WHERE #T_MAN_REPORT.GUID =B.GUID
CREATE TABLE #T_MAX_ID
(
ID INT NULL,
GUID VARCHAR(30) NULL,
STATEID INT NULL,
INFO INT NULL
)
INSERT INTO #T_MAX_ID( ID,GUID,STATEID,INFO)
SELECT ID,GUID,STATEID,INFO FROM
T_B_REPORT_TRANSMIT WHERE ID IN (SELECT MAX(ID) FROM T_B_REPORT_TRANSMIT GROUP BY GUID)
UPDATE #T_MAN_REPORT
SET #T_MAN_REPORT.STATEID=B.STATEID, #T_MAN_REPORT.INFO=B.INFO
FROM #T_MAN_REPORT ,#T_MAX_ID AS B WHERE #T_MAN_REPORT.ID =B.ID
UPDATE #T_MAN_REPORT
SET #T_MAN_REPORT.PLANYEAR=B.PLANYEAR, #T_MAN_REPORT.PROJECTNAME=B.PROJECTNAME
FROM #T_MAN_REPORT ,T_B_PLAN AS B WHERE #T_MAN_REPORT.PLANID =B.PLANID
UPDATE #T_MAN_REPORT
SET #T_MAN_REPORT.A_COUNT =B.A_COUNT
FROM #T_MAN_REPORT ,V_B_AUDITREPORT_ATTACOUNT AS B WHERE #T_MAN_REPORT.GUID =B.GUID
UPDATE #T_MAN_REPORT
SET #T_MAN_REPORT.INFONAME =B.NAME
FROM #T_MAN_REPORT ,T_B_COMBOX AS B WHERE #T_MAN_REPORT.INFO =B.ID AND B.TYPEID = 41
UPDATE #T_MAN_REPORT
SET #T_MAN_REPORT.STATENAME=B.NAME
FROM #T_MAN_REPORT ,T_B_COMBOX AS B WHERE #T_MAN_REPORT.STATEID =B.ID AND B.TYPEID = 33
UPDATE #T_MAN_REPORT
SET #T_MAN_REPORT.SIGNNAME =B.SIGNNAME
FROM #T_MAN_REPORT ,T_S_USER AS B WHERE #T_MAN_REPORT.OUSERID =B.USERID
SELECT PLANYEAR AS '审计年度', PLANID AS '项目编号', PROJECTNAME AS '项目名称', UNIONID AS '审计报告编号',
RPTNAME AS '审计报告名称', SIGNNAME AS '发送人', CREATETM AS '创建时间',STATENAME AS '状态', INFONAME AS '文件类型',
A_COUNT AS '附件数',DOCMODELID AS '文档模板序号', OUSERID AS '创建人编号', STATEID AS 文档状态编号,INFO AS '文档说明编号',
GUID,NEWGUID,ID AS TRANSMITID,DOCID,USERID AS ORIGINALITYMANID FROM #T_MAN_REPORT
DROP TABLE #T_MAX_ID
DROP TABLE #T_MAN_REPORT
END
/*
DROP PROC P_S_GETMANALLUNIONREPORT_EDIT
EXEC P_S_GETMANALLUNIONREPORT_EDIT '0021'
*/