存储过程中的记录计数

时间:2016-03-03 12:42:44

标签: sql sql-server

我有一个从TBL_DOMAIN INSERT INTO TBL_STAGING的SP,但首先我要检查表TBL_STAGING以确保在截断表TBL_DOMAIN之前表不为空,如果表TBL_STAGING有多个记录,则继续截断表TBL_DOMAIN然后运行INSERT,ELSE消息,表示表TBL_STAGING为EMPTY并退出SP。我的目标是确保表TBL_DOMAIN仍然有数据甚至是旧的。我是非常新的SQL请帮忙。

CREATE PROCEDURE [dbo].[SP_INSERT_ALL_DOMAIN]
WITH EXECUTE AS CALLER
AS
BEGIN      

 BEGIN TRANSACTION NT_ALL_DOMAIN 
    INSERT INTO  TBL_DOMAIN
        (DOMAIN_NAME,
        DISTINGUISHED_NAME,
        EMAIL_ADDR_I)
    SELECT  DOMAIN_NAME,  
        DISTINGUISHED_NAME,
        EMAIL_ADDR_I
    FROM TBL_STAGING

1 个答案:

答案 0 :(得分:1)

首先,您需要检查TBL_STAGING是否有数据:

=Sum(iif( 
Fields!Sub.Value = "Ins", 
0, 
IIF(Fields!Sub.Value = "Ins - Int", 0, Fields!A.Value)
))