I want to verify if there is a database BDDATOS1, if it exists I create a table in this database BDDATOS1, otherwise I create a table in database BDDATOS2.
When I run the following
IF EXISTS(SELECT * FROM master.dbo.SYSDATABASES WHERE NAME = 'BDDATOS1')
CREATE TABLE BDDATOS1.._articulos2 ([carticulos_id] [char] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [cagrupacion_articulos_id] [char] (9) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [carticulos_nombre] [char] (80) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL );
else
CREATE TABLE BDDATOS2.._articulos2 ([carticulos_id] [char] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [cagrupacion_articulos_id] [char] (9) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [carticulos_nombre] [char] (80) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL );
end
gives me a pre-execution error saying that BDDATA1 does not exist, which is true, but it is assumed that it should go to the ELSE statement and create the table in database BDDATOS2.
This error only comes up with create, with UPDATE, SELECT and DROP it does not give me an error.