I am trying to write a CTE to control when an insert process runs.
I keep having problems with the IF statement.
Thanks
John Fuhrman
I keep having problems with the IF statement.
Code:
WITH
cteTotals (TTL_Prod, TTL_Dev)
AS
(
Select
(Select Count(*) From MailroomTracking.dbo.tblTrackingTable),
(Select Count(*) From MailroomTracking_DEV.dbo.tblTrackingTable)
)
--Select Sum(TTL_Prod-TTL_Dev) From cteTotals
--Select
-- TTL_Prod,
-- TTL_Dev,
-- Sum(TTL_Prod-TTL_Dev) As New_Rows
--From cteTotals
--Group by TTL_Prod, TTL_Dev
If (Select Sum(TTL_Prod-TTL_Dev) From cteTotals) > 0
Begin
Print 'Perform Insert'
End
Else
Print 'No new rows'
Thanks
John Fuhrman