Ms Sql If Exist

Ms Sql If Exist


  There are situations where you would like to perform some operations on table based on certain conditions

e.g. You would like to transfer some data from one table to another table but the condition is that should have less than 100 rows

Trick: use if statement instead of taking temporary variable

if ( (select count(*) from xyxTable with (nolock)) < 100)
begin

-- Do something

end

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5