Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to drop table in script per loop having square brackets in its name?

Hi there,

assuming a generic load created tables called e.g. like this:

Value_at_0,5_bar_[l/min]

Value_at_[°KW]

(Yes, including the square brackets around the unit)

I want to delete them automatically at the end of the load script using the usual for-loop. But I don't find the correct phrasing for the drop statement. Has someone an idea?

Thanks a lot in advance,
Martin

7 Replies
Not applicable
Author

evan_kurowski
Specialist
Specialist

You could try switching to wrapping the table name with graves accent - ` - chr(96)

Not applicable
Author

Try based on this example


SUB WildcardDropTables (vExpression)

    // Loop through the tables within the model

    FOR i = 0 TO noOfTables()-1 STEP 1

      

        // Get the current table name

        LET vCurrTable = tablename(i); // Get the current table name

  

        // If the table name matches the pattern then drop it

        IF wildmatch('$(vCurrTable)','$(vExpression)') THEN

            DROP Table [$(vCurrTable)];

            LET i = i - 1; // Needed as table index reduces once table is dropped

        END IF  

      

    NEXT

    // Clear the variables so they don't persist

    LET vExpression = null();

    LET vCurrTable = null();

END SUB


CALL WildcardDropTables ('*-temp')



evan_kurowski
Specialist
Specialist

That is a nice usage of the wildcard Ramkumar,  will have to remember that.

I think if you count backwards from NoOfTables()-1 to 0 you don't have to keep resetting i.

Not applicable
Author

Hi Evan,

I am afraid the ` won't be accepted. How could a drop table statement look like with the examples above?

My problem is not creating the loop, much more the drop table statement ( I can also write the drop-statements manually behind each other if necessary.

Thanks again,

Martin

evan_kurowski
Specialist
Specialist

Hello Martin,

I'm not able to reproduce your issue.  I created a variety of tables with programmatic characters embedded in the table names and am able to drop them in a for-loop using the same DROP statement across all tables.

Maybe there are some scenarios I missed or it is a version thing?

20140812_Covering_programmatic_characters.png

Not applicable
Author

Hi Evan,

thanks a lot for your work.... it is really strange, obviously it SHOULD work... I will investigate further and let you know when I have a result. 🙂

Cheers,

Martin