Subscribe to this thread
Home - General / All posts - Using a variable name in place of a table name
#15-Jan-21 01:48

I wish to process many tables with the same SQL code - take data from an imported table and then create a new table and drawing.

I am attempting to generate a general Query for this purpose where I simply add the imported table name at the top as a global variable and then all else would follow. I then generate other global variables based on this name.

I had thought of the following code included below as the start but found it did not work. I then created the table with hard wired names and read the PragmaValue name into a global variable. But this did not work for the functions that followed. I assume that i am not using the global variables correctly in place of table names. All the examples I have seen relate to the use of global variables in field names rather than table names.

I would greatly appreciate some guidance here.

Many thanks

Example code

VALUE @ImportedTableName NVARCHAR = '[ImportedTable]'

VALUE @NewDrawingName NVARCHAR = @ImportedTableName + '_Lines'

VALUE @NewTableName NVARCHAR = @NewDrawingName + 'Table'

CREATE TABLE @NewTableName (

[mfd_id] INT64,

[LineID] INT32,

[Points] INT32,

[Geom] GEOM,

INDEX [mfd_id_x] BTREE ([mfd_id]),

INDEX [Geom_x] RTREE ([Geom]),

PROPERTY 'FieldCoordSystem.Geom' ComponentFieldCoordSystem(@ImportedTableName, 'Geom')

);

INSERT INTO @NewTableName (

[LineID],

[Points],

[Geom]

) SELECT

[LineID],

Count([Point]),

GeomMergePoints([Geom])

FROM @ImportedTableName GROUP BY [LineID];

];

Manifold User Community Use Agreement Copyright (C) 2007-2019 Manifold Software Limited. All rights reserved.