sqlserver 判断某个表不存在就新建表,然后插入数据

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值