Wiki

Scale Your Enterprise

User Tools

Site Tools


bw:sql_command_tool

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
bw:sql_command_tool [2019/10/23 16:37]
akoehler [Post Execution Query (SQL Server only)]
bw:sql_command_tool [2022/08/02 10:35] (current)
akoehler [SQL System Variables]
Line 16: Line 16:
 The following pages contain additional information that may be helpful with the development of Bizweaver workflows using the SQLCommand tool. The following pages contain additional information that may be helpful with the development of Bizweaver workflows using the SQLCommand tool.
  
-  * [[bw:global_connections|Global Connections]]+  * **[[bw:global_connections|Global Connections]]**
  
 ====== Before You Begin ====== ====== Before You Begin ======
Line 42: Line 42:
 Four SQL Server command types are supported: Four SQL Server command types are supported:
  
-  * **//[[bw:global_connections#Reader (SQL Server and HANA)|Reader]]//** +  * **//[[bw:sql_command_tool#Reader (SQL Server and HANA)|Reader]]//** 
-  * **//[[bw:global_connections#Non-Query (SQL Server only)|Non-Query]]//** +  * **//[[bw:sql_command_tool#Non-Query (SQL Server only)|Non-Query]]//** 
-  * **//[[bw:global_connections#Post Execution Query (SQL Server only)|Post Execution Query]]//** +  * **//[[bw:sql_command_tool#Post Execution Query (SQL Server only)|Post Execution Query]]//** 
-  * **//[[bw:global_connections#Stored Procedure (SQL Server only)|Post Execution Query]]//**  +  * **//[[bw:sql_command_tool#Stored Procedure (SQL Server only)|Stored Procedure]]//**  
  
 ===== HANA ===== ===== HANA =====
Line 59: Line 59:
     - When variables are used, they are subject to standard syntax rules regarding text vs. numeric values. This means that text variables MUST be enclosed in single quotes.     - When variables are used, they are subject to standard syntax rules regarding text vs. numeric values. This means that text variables MUST be enclosed in single quotes.
  
-The following image shows same SELECT statement as illustrated above, but with a variable in the WHERE clause.+The following image shows the same SELECT statement as illustrated above, but with a variable in the WHERE clause.
  
 {{  :bw:sqlimage2.png?411x72  }} {{  :bw:sqlimage2.png?411x72  }}
  
 +
 +<WRAP center round important>
 +When saving a workflow or opening the SQL/HANA tool or the workflow, the reader command type will validate the written query. This executes the query against the connected database. **There is the ability to have Non-query commands written using the Reader command type. This will execute the statement against the database. If a Create, Update, Insert, Truncate or Delete (any SQQL/HANA statement that affects a change to any data) is written, the command will execute and be run against the connected database if the workflow is saved or the tool or workflow is opened**
 +</WRAP>
 ===== Non-Query (SQL Server only) ===== ===== Non-Query (SQL Server only) =====
  
-  - This command is used for UPDATE, INSERT, and DELETE statements.+  - This command is used for **UPDATE, INSERT, DELETE and STORED PROCEDURES** with or without Parameters statements.
     - Variables representing values from previous steps can be used in the statement as needed. Press <F4> for a list of available variables.     - Variables representing values from previous steps can be used in the statement as needed. Press <F4> for a list of available variables.
     - Keep in mind that these statements will affect your data immediately. **Use them with care**.     - Keep in mind that these statements will affect your data immediately. **Use them with care**.
 +    - Non-Query cannot be test run
  
 <WRAP center round important> <WRAP center round important>
-**For SAP Business One Users**: Updates to standard SAP Business One tables should not be done directly using insert, update, or delete. These updates should be done using the **//[[bw:sap_business_one_integration_for_sql_server_databases#Mapper Tool|Mapper]]//** & **//[[bw:sap_business_one_integration_for_sql_server_databases#SBO Update|SBO Updater]]//** tools.+**For SAP Business One Users**: Updates to standard SAP Business One tables should not be done directly using insert, update, or delete. These updates should be done using the **//[[bw:sap_business_one_integration_using_di#Mapper Tool|Mapper]]//** & **//[[bw:sap_business_one_integration_using_di#SBO Update|SBO Updater]]//** tools.
 </WRAP> </WRAP>
  
Line 82: Line 87:
 {{  :bw:sqlimage3.png?384x288  }} {{  :bw:sqlimage3.png?384x288  }}
  
-===== Stored Procedure (SQL Server only) =====+=====Stored Procedure (SQL Server only) =====
  
 This command can be used to execute a SQL Stored Procedure that does not require parameters. In this case the “exec” statement is not used. All that is required is the name of the procedure. In most cases, it is probably easier to simply always use the Non-Query option to avoid confusion. Use of the Non-Query option is described above. This command can be used to execute a SQL Stored Procedure that does not require parameters. In this case the “exec” statement is not used. All that is required is the name of the procedure. In most cases, it is probably easier to simply always use the Non-Query option to avoid confusion. Use of the Non-Query option is described above.
  
-==== Stored Procedures (SQL Server only) ====+====Passing Parameters using  Stored Procedures (SQL Server only) ====
  
 While there is a “Stored Procedure” command in the SQL Command tool drop down menu, its use is currently limited as it does not support the use of input parameters. To address this, the **Non-Query** command can also be used to execute stored procedures that include parameters for execution. In this case the “exec” statement must be included in the command. The parameters are passed using standard SQL Server syntax. For example, assume a stored procedure that includes two parameters. The SQL statement would be: While there is a “Stored Procedure” command in the SQL Command tool drop down menu, its use is currently limited as it does not support the use of input parameters. To address this, the **Non-Query** command can also be used to execute stored procedures that include parameters for execution. In this case the “exec” statement must be included in the command. The parameters are passed using standard SQL Server syntax. For example, assume a stored procedure that includes two parameters. The SQL statement would be:
Line 99: Line 104:
   - Any “calculated” value in a SQL statement must have an alias assigned for it to be available in Bizweaver. This applies to numeric calculations, concatenated text values, CASE values, and any other instance where the value is not a column name in a table. Standard syntax rules apply for assigning alias names.   - Any “calculated” value in a SQL statement must have an alias assigned for it to be available in Bizweaver. This applies to numeric calculations, concatenated text values, CASE values, and any other instance where the value is not a column name in a table. Standard syntax rules apply for assigning alias names.
   - When using the {RetKey} variable in a SQL Command statement, it should always be enclosed in single quotes. If this is not done the validation process will raise an error.   - When using the {RetKey} variable in a SQL Command statement, it should always be enclosed in single quotes. If this is not done the validation process will raise an error.
-  - When variables are used in a SQL statement, the normal rules regarding quotes apply. This means that if the value represented by the variable is a string, the variable in the statement should be enclosed in single quotes as well. For example, the value ItemCode is selected in a Reader step named “GetData.” When this value is used in a subsequent step the associated variable is enclosed in single quotes as shown here:+  - When variables are used in a SQL statement, the normal rules regarding quotes apply. This means that if the value represented by the variable is a string, the variable in the statement should be enclosed in single quotes as well. For example, the value ItemCode is selected in a Reader step named “GetData”When this value is used in a subsequent step the associated variable is enclosed in single quotes as shown here:
  
  <code>'WorkFlow(GetData).Get({FIELD_ItemCode})'</code>  <code>'WorkFlow(GetData).Get({FIELD_ItemCode})'</code>
  
 ====== SQL Test Run Option ====== ====== SQL Test Run Option ======
-Bizweaver v2.3 introduces the **Test Run** option in the SQLCommand tool.  This option allows you to test SQL functions without running through the entire workflow.  It also allows you to test SQL steps where the input involves variables from previous steps.  The example here uses the following SQL statement.+Bizweaver version 2.3 introduces the **Test Run** option in the SQLCommand tool.  This option allows you to test SQL functions without running through the entire workflow.  It also allows you to test SQL steps where the input involves variables from previous steps.  The example here uses the following SQL statement.
  
-{{:bw:sqlimage4.png?500|SQL statement}}+{{ :bw:sqlcommandtooltestrunstep1.png?500 |}}
  
 To invoke this option click on the "Test Run" link in the lower-right corner of the tool window.  The display changes to the test view. To invoke this option click on the "Test Run" link in the lower-right corner of the tool window.  The display changes to the test view.
  
-{{:bw:sqlimage5.png?400|SQL statement}}+{{ :bw:testrunstep2.png?nolink |}}
  
-The [Result] tab displays the results of the SQL statement.  The statement can be modified in this tab to add/change the statement as needed for testing.  This includes adding/changing variable values.  Click the green <color #22b14c>Run</color> link to execute the modified statement.  This may be done as many times as needed.+Test view 
 + 
 +{{ :bw:sqlcommandtooltestrunstep3.png?nolink&500 |}} 
 + 
 +The [Result] tab displays the results of the SQL statement.  The statement can be modified in this tab to add/change the statement as needed for testing.  This includes adding/changing variable values.  Click the green <color #22b14c>Run</color> link to execute the modified statement.  This may be done as many times as needed.  
 + 
 +{{ :bw:runstep4.png?nolink |}}
  
 In this example we can enter a valid value where the variable will be used to test the statement. In this example we can enter a valid value where the variable will be used to test the statement.
Line 121: Line 132:
  
 <WRAP center round important 60%> <WRAP center round important 60%>
-Changes in the [Result] tab DO NOT automatically carry back to the [SQL] tab.  If you make changes in the [Result] tab that need to be in the "real" SQL statement, you must add them manually.+Changes in the [Result] tab **DO NOT** automatically carry back to the [SQL] tab.  If you make changes in the [Result] tab that need to be in the "real" SQL statement, you must add them manually. Once the test is modified you should copy the code and then exit the test view and past them in the SQL section for best results.
  
 Click the green <color #22b14c>Run</color> link to execute tests.  If you click the "Test Run" link again the results will revert to the statement in the [SQL] tab. Click the green <color #22b14c>Run</color> link to execute tests.  If you click the "Test Run" link again the results will revert to the statement in the [SQL] tab.
 </WRAP> </WRAP>
 +
 +
 +====== SQL System Variables ======
 +
 +^ Name           ^ Description         ^
 +| CommandType       | The command type chosen in the SQL tool ex. Reader, Non-Query      |
 +| DataSourceFields |The fields pulled from the data source will only show up when executing the query in the SQL tool and not during a test run|
 +| DataSourceResultsTable         | The results from executing the query in the workflow. Will only show up when executing the query in the SQL tool and not during the test run      |
 +| QueryString         | The current query that is being executed     |
 +| SQLCommand        | Used for an older version of Bizweaver no longer returns a value    |
 +| SQLResultsCount         | The total amount of records that were retrieved during a query       |
 +|StepMessage       | During a failure the reason for failure will be populated here     |
 +| StepStatus        | True or False     |
 +
 +
 +======SQL Tips======
 +  * [[bw:sql tools|Strip HTML Tags From Input String]]
  
  
  
bw/sql_command_tool.1571863048.txt.gz · Last modified: 2019/10/23 16:37 by akoehler