Skip to main content
Question

SQL To Run after Wrtite -Incorrect Syntax - Provider error `(-2147217900). Adding a named constraint primary key

  • June 17, 2020
  • 1 reply
  • 121 views

moraalejandra93
Participant
Forum|alt.badge.img

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

1 reply

erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • June 17, 2020

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings