MSCEWI4021

If Statement With Object ID Removed

triangle-exclamation

Severity

Low

Description

This EWI is added when SnowConvert removes an ObjectID function since its functionality is handled by the following statement. This happens when an ObjectID function is a condition for an If Statement and the body of this statement has a Create or Drop Table.

Code Example

Input Code:

IF OBJECT_ID(N'dbo.MyTable0', N'U') IS NOT NULL  
   DROP TABLE [dbo].[MyTable0];  

IF OBJECT_ID('DBO.MYTABLE1', N'U') IS NULL
BEGIN
   CREATE TABLE DBO.MYTABLE1(COL1 VARCHAR(200))
END

Output Code:

EXEC(`DROP TABLE IF EXISTS PUBLIC.TABLETEST`);
// ** MSC-WARNING - MSCEWI4021 - IF STATEMENT WITH OBJECT_ID FUNCTION REMOVED AND REPLACED FOR A CREATE OR DROP TABLE STATEMENT. **
EXEC(`DROP TABLE IF EXISTS dbo.MyTable0`);
// ** MSC-WARNING - MSCEWI4021 - IF STATEMENT WITH OBJECT_ID FUNCTION REMOVED AND REPLACED FOR A CREATE OR DROP TABLE STATEMENT. **
{
   EXEC(`CREATE OR REPLACE TABLE DBO.MYTABLE1(COL1 VARCHAR(200))`);
}

Recommendations

Last updated