How to verify if a table is empty during executing a statement

  • My problem is:

    I would like to fill a table with:

    Insert into TDest Select * from Tsource

    The problem is that: If Tsource is empty, I would like to perform a task tell that the table Tsource is empty.

    I think:

    Insert into TDest Select * from Tsource

    IF @@rowcount = 0 .....

     

    Is there another way to do it (I do not want to verify if the table is empty Like: count(), but directly or after the statement: Insert into TDest Select * from Tsource)

    Thank

     

  • I completely misunderstood your post. 

    IF EXIST( SELECT TOP 1 * FROM Tsource)

    BEGIN

         ... do your work

    END

    ELSE

    BEGIN  

         RETURN

    END

    I wasn't born stupid - I had to study.

  • You have understood very well

    Thank

  •   I changed my first post... 

    I wasn't born stupid - I had to study.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply