beckhoff TS6420 — 8.6 Stored Procedures with MS SQL

Samples The following example shows the call of a stored procedure with an input parameter and a return data set for a customer and production database sample. The procedure was generated at a Microsoft SQL Server 2008.

Code of the stored procedure SP_GetAddressByCustomerID CREATE PROCEDURE [SP_GetAddressByCustomerID] @Customer_ID bigint AS BEGIN SELECT tbl_Customer.ID, tbl_Customer.Name, tbl_Customer.Customer, tbl_Products.SerNum, tbl_Produ cts.Product, tbl_Products.Info, tbl_Pos.Timestamp FROM tbl_Pos JOIN tbl_Customer ON tbl_Pos.CustomerNum = tbl_Customer.ID JOIN tbl_Products ON tbl_Pos.ProductNum = tbl_Products.SerNum WHERE tbl_Pos.CustomerNum = @Customer_ID; END Variable declaration in the PLC PROGRAM MAIN VAR R_TRIG1: R_TRIG; bREAD : BOOL := FALSE; nState: BYTE; arrParaList: ARRAY [0..0] OF ST_DBParameter; nCustomerID: DINT := 12345; TS6420 116 Version:

1.2 Used database type MS SQL (MS SQL Server 2008) Compatible database types MS SQL Used function blocks FB DBStoredProceduresRecordReturn _ Integrated libraries "TcDatabase.lib", "TcSystem.lib","TcBase.lib","TcStandard.lib" Download data list FB DBStoredProcedures Sample.pro, CurrentConfigDataBase.xml, _ _ SQLQuery2.sql