Skip to main content

Hi guys, I'm trying to add a named constraint primary key into a large number of SQL Server tables joined in one reader with this code in the 'SQL to Run after Write' part:

0684Q00000ArAh2QAF.jpg

 

FME_SQL_DELIMITER ;

ALTER TABLE @Value(fme_basename)
ADD CONSTRAINT PK_@Value(fme_basename) PRIMARY KEY (id1)

But I got this error:

Microsoft SQL Server Spatial Writer: Query failed, possibly due to a malformed statement.  Query Text `ALTER TABLE @Value(fme_basename)

ADD CONSTRAINT PK_@Value(fme_basename) PRIMARY KEY (Id1)'. Provider error `(-2147217900) Incorrect syntax near '@Value'.'

 

Does anyone know what is the error? Or how can add a Primary Key for a large number of tables joined in one reader?

 

Thanks a lot

Not sure you can use attributes in the After SQL statement.

A way to solve this is:

Use the FeatureWriter instead of the writer.

On the Summary output you have a list of feature types (tables) that are written to.

You can use that list (ListExploder) followed by a SQLExecutor to create the constraints.

 

Another thought:

fme_feature_type should be the fme attribute that contains the name of the table, not fme_basename.

 

Hope this helps.


Reply