javierb
Posts: 1
Joined: Mon Jul 09, 2018 2:04 am

Set property with SQL Query, after a SQL Script

My project is executing several SQL scripts (with replacement) in the installation
1. Script 1, creates the Schema of the Database
2. Script 2 inserts static catalogs.
3. Script 3 inserts some tables that have a Identity column (ID)

At this point, after script 3, i need to save the last ID inserted in a property. For example:

SELECT IDENT_CURRENT('[Schema1].[MyTAble]') as lastId

And set this value in a global PROPERTY. THe issue is that I didn't find a way to execute this QUERY after the script #3 is finished

Please help.
Catalin
Posts: 6584
Joined: Wed Jun 13, 2018 7:49 am

Re: Set property with SQL Query, after a SQL Script

Hello and welcome to our forums,

First of all, if you are using our predefined support for SQL Scripts, there is no way to achieve what you want, because the scripts are running during "Install Execution Stage" -> "Add Resources" (On deferred). That means that you should've added your query after the "Add Resources" action group. The problem here consists of the fact that when the system is being modified (deferred), you don't have access to the properties, which leads to the query being unable to store the result in a property.

As a workaround, you can use our predefined support for SQL query and use queries instead of scripts, since a query can be placed wherever you want in the "Action Group". For instance, you can create 4 queries and place their actions before "Add Resources" action group, with the "Execution Time" as "Immediately".

Hope this helps!

If you have any further questions or doubts, don't hesitate to contact me and I'll gladly assist.

Regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”