SQL-如果行数大于 [英] SQL - Insert if the number of rows is greater than

查看:99
本文介绍了SQL-如果行数大于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个SQL查询,该查询将从Oracle链接服务器返回行.该查询工作正常,例如将返回40行.我希望仅在返回的行数大于40的情况下将结果插入表中.

I have created a SQL query that will return rows from an Oracle linked server. The query works fine and will return 40 rows, for example. I would like the results to only be inserted into a table if the number of rows returned is greater than 40.

然后我的想法是,我可以创建一个触发器来发出一封电子邮件,指出该号码已被破坏.

My thinking would then be that I could create a trigger to fire out an email to say the number has been breached.

推荐答案

DECLARE @cnt INT

SELECT @cnt = COUNT(*) FROM LinkedServer.database.schemaname.tablename

IF @cnt > 40

INSERT INTO table1 VALUES(col1, col2, col3 .....)

这篇关于SQL-如果行数大于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆