TSQL count(*) then UPDATE

  • Can anyone suggest an alternative (faster way) to setting this variable '@count';

    SELECT @count = COUNT(*)

    FROM VendorLargeTable

    WHERE ColumnName = @Variable

    AND Id = @ID

    The t-sql then goes on to do something like if @count > 0 then update .....

    Would there be a way to use a top somehow? Instead of going though the whole table we just want to know if there is more than 0 records meeting the condition. I would think that once 1 is found we could stop the search?

    Any assistance would be greatly appreciated!

  • use an existance query, like:

    if exists(SELECT 1 FROM VendorLargeTable WHERE ColumnName = @Variable AND Id = @ID)

    update VendorLargeTable set ......

    The probability of survival is inversely proportional to the angle of arrival.

Viewing 2 posts - 1 through 1 (of 1 total)

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