ALTER PROCEDURE [dbo].[yz_test]
AS
BEGIN
IF NOT EXISTS (select * from dbo.sysobjects where xtype='U' and Name = 'yz' )
BEGIN
CREATE TABLE [dbo].[yz] (
[说明] varchar(255) COLLATE Chinese_PRC_CI_AI_KS NULL ,
[总数] varchar(255) COLLATE Chinese_PRC_CI_AI_KS NULL
)
ON [PRIMARY];
END
INSERT into yz
SELECT '本批数据总共多少人?' as aa, COUNT(*) from BA_SYJBK;
INSERT into yz
SELECT '文书表是否都能关联上中间表?',iif(count(*) -(SELECT COUNT(*) from EMR_QTBLJLK )=0,'true','false') from CPOE_BRSYK A JOIN EMR_QTBLJLK B ON A.EMRXH=B.SYXH;
INSERT into yz
SELECT '文书表能关联上中间表的个数',count(*) from CPOE_BRSYK A JOIN EMR_QTBLJLK B ON A.EMRXH=B.SYXH;
INSERT into yz
SELECT '文书表的个数',COUNT(*) from EMR_QTBLJLK;
INSERT into yz
SELECT '首页表是否都能关联上中间表?',iif(count(*)-(SELECT COUNT(*) from BA_SYJBK)=0,'true','false') from CPOE_BRSYK A JOIN BA_SYJBK B ON A.BLH=B.bahm
SELECT '首页能关联上中间表的个数',count(*) from CPOE_BRSYK A JOIN BA_SYJBK B ON A.BLH=B.bahm;
INSERT into yz
SELECT '首页的个数',COUNT(*) from BA_SYJBK;
INSERT into yz
SELECT '文书中有多少个人?',COUNT(*) from
(SELECT count(*) as num FROM
(SELECT A.SYXH,A.BLH from CPOE_BRSYK A JOIN EMR_QTBLJLK B ON A.EMRXH=B.SYXH)T1 JOIN BA_SYJBK T2
ON T1.BLH=T2.bahm
GROUP BY T1.SYXH)M;
END
sqlserver 判断某个表不存在就新建表,然后插入数据
最新推荐文章于 2024-08-25 20:57:14 发布