Check whether Sql table is empty or not

Hi,

How can I check whether Sql table is empty or not? I want to insert data if it is empty. Any help?

check the rows count

e.g. directly in SQL: SELECT COUNT(*) FROM YourTableName

@WASEEM_KHAN

  1. Use Execute Query activity and write Select Query and it will give output as DataTable. let’s say ‘InputDT’.

  2. And then check row count like below.

      InputDT.Rows.Count
    
  3. If it is greater than 0 then data exists else not.

Hi @WASEEM_KHAN

Use Execute Query from data base activities

In Excecute Query fill the connection name properties and query as

Select * from table name;

Out as datatable

Check count with Datatable.rows.count if the count is zero then excecute Query and Insert

Regards

This is a lot of extra overhead for no reason, if there is data in the SQL table.

Better to just do a SELECT COUNT query and get back the number.

Hi! I wrote this sql statement in execute query activity. Now this activity returns a datatble.
I want to check, whether the sql table is empty or not. How can I apply an If check on the result of the above query?

@WASEEM_KHAN

Check row count of that Output DataTable. If it is 0 then it is empty else not.

           InputDT.Rows.Count