CREATE FUNCTION [dbo].[TableExists] (@ATableName VARCHAR(200))
RETURNS BIT AS
BEGIN
  /*
    Created by Kent Johansen December 2008
  */

  DECLARE @Return INT

  SELECT @Return = COUNT(*) FROM sysobjects WITH (NOLOCK)
  WHERE sysobjects.Name = @ATableName
  AND sysobjects.xType = 'u'

  IF @Return > 0
    SET @Return = 1
  ELSE
    SET @Return = 0
  RETURN @Return
END