Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - Insert if the number of rows is greater than

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.

like image 935
stevenk Avatar asked Jan 19 '26 05:01

stevenk


1 Answers

DECLARE @cnt INT

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

IF @cnt > 40

INSERT INTO table1 VALUES(col1, col2, col3 .....)
like image 164
Kalyan Avatar answered Jan 20 '26 22:01

Kalyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!