Query panel in the Promotion formula window
Query panel in the Promotion formula window

The Query panel contains the text of the SQL query for the database. This query is used to generate data for the calculation of the discount (or markup) value:

Figure 6.201. Query panel


The panel contains a multiline field for entering an SQL query.

The information that is required for calculation of the discount/markup value is stored in the program's database. Data that are required to calculate a particular discount or markup are gathered using queries written in the Transact SQL language (SQL queries).

Figure 6.202. Query panel with its context menu


The context menu of the field in the Query panel contains the Test query command. This command is only available if the Query panel field contains the text of a query. This command checks whether the query text has any errors. After the check has been completed, a window containing the result of the query execution opens.

When testing the query, you need to select filter parameter values at every filter step. After the query has been successfully completed, a message appears that notifies you about the successful completion of the query.

Figure 6.203. Query successfully completed message


If any errors occur during the execution of the query, an error message will appear.

The following parameters can be used in the query:
       CREATE TABLE #Notes(
            note_ID                      UNIQUEIDENTIFIER PRIMARY KEY,
            note_nttp_ID            UNIQUEIDENTIFIER,
            note_Item_ID            UNIQUEIDENTIFIER,
            note_obj_ID       UNIQUEIDENTIFIER,
            note_tpsyso_ID          UNIQUEIDENTIFIER,
            note_Date               DATETIME,
            note_Value        SQL_VARIANT
      )


        CREATE TABLE #Guests(       
            gest_ID                       UNIQUEIDENTIFIER PRIMARY KEY, 
            gest_gsst_ID                  INT, 
            gest_dvsn_ID                  UNIQUEIDENTIFIER, 
            gest_SalePrivilegeData        VARBINARY(MAX), 
            gest_InformationTransactionID UNIQUEIDENTIFIER,
            gest_sprv_ID                  UNIQUEIDENTIFIER, 
            gest_clnt_ID                  UNIQUEIDENTIFIER, 
            gest_ClientName               NVARCHAR(MAX) COLLATE DATABASE_DEFAULT,
            gest_idnt_ID                  UNIQUEIDENTIFIER, 
            gest_usr_ID                   UNIQUEIDENTIFIER, 
            gest_plac_ID                  UNIQUEIDENTIFIER, 
            gest_PlaceNumber              INT, 
            gest_dev_ID                   UNIQUEIDENTIFIER, 
            gest_lggr_ID                  UNIQUEIDENTIFIER, 
            gest_dev_ID_SalePrivilege     UNIQUEIDENTIFIER, 
            gest_DateOpen                 DATETIME, 
            gest_DateClose                DATETIME,
            gest_Name                     NVARCHAR(MAX) COLLATE DATABASE_DEFAULT, 
            gest_Count                    INT, 
            gest_Comment                  NVARCHAR(MAX) COLLATE DATABASE_DEFAULT
    )

-- Order items 
CREATE TABLE #OrderItems( -- Info fields. Can be used for adding items 
  i_ID UNIQUEIDENTIFIER PRIMARY KEY, -- Order item ID          i_ordr_ID UNIQUEIDENTIFIER, -- Order ID 
  i_PriceOriginal NUMERIC(18,4), -- Price without discounts or markups 
  
-- Info fields 
  i_Date DATETIME, -- Order submitted date 
  i_pcit_ID UNIQUEIDENTIFIER, -- Bill item ID                  i_LastPriceDiscount NUMERIC(18,4) NULL, -- Value of the previously applied discount. Specified only if i_pcit_ID is not NULL 
  i_LastPriceMargin NUMERIC(18,4) NULL, -- Value of the previously applied markup. Specified only if i_pcit_ID is not NULL 
  i_LastPrice NUMERIC(18,4) NULL, -- Price after previously applied discount/markup. Specified only if i_pcit_ID is not NULL 

  -- Info fields. Can be edited. Used for adding items         i_master_ID UNIQUEIDENTIFIER, -- Parent item ID  
  i_mitm_ID UNIQUEIDENTIFIER, -- Menu item ID 
  i_mish_ID UNIQUEIDENTIFIER, -- Menu item shortcut ID         i_slgr_ID UNIQUEIDENTIFIER, -- Sales department ID           i_mvtp_ID UNIQUEIDENTIFIER, -- ID for menu unit of measurement 
  i_Order INT, -- Index 
  i_Count INT, -- Number of portions 
  i_Volume NUMERIC(18,6), -- Quantity 
  i_PriceDiscount NUMERIC(18,4) DEFAULT 0, -- Discount  
  i_PriceMargin NUMERIC(18,4) DEFAULT 0, -- Markup 

-- Control fields 
  i_ModifyAction INT DEFAULT 1, -- 1 - add, 2 - edit, 3 - delete 

-- command fields 
  i_Price AS (i_PriceOriginal - i_PriceDiscount + i_PriceMargin), -- Price 
  i_ForUpdate BIT DEFAULT 0 -- Indicates that this item must be recalculated ) 

-- Timed services in the order 
CREATE TABLE #OrderTimeItems( 
-- Info fields 
  t_ID UNIQUEIDENTIFIER PRIMARY KEY, -- ID for a price schedule of a timed service in the order 
  t_orti_ID UNIQUEIDENTIFIER, -- ID of a timed service in the order 
  t_ordr_ID UNIQUEIDENTIFIER, -- Order ID 
  t_plac_ID UNIQUEIDENTIFIER, -- Table ID 
  t_pcit_ID UNIQUEIDENTIFIER, -- Bill item ID                  t_LastPriceDiscount NUMERIC(18,4) NULL, -- Value of the previsouly applied discount. Specified only if i_pcit_ID is not NULL 
  t_LastPriceMargin NUMERIC(18,4) NULL, -- Value of the previously applied markup. Specified only if i_pcit_ID is not NULL 
  t_LastPrice NUMERIC(18,4) NULL, -- Price after previously applied discount/markup. Specified only if i_pcit_ID is not NULL 
  t_PriceOriginal NUMERIC(18,4), -- Price without discounts or markups 

-- Info fields. Can be edited. 
  t_master_ID UNIQUEIDENTIFIER, -- Parent item ID 
  t_mitm_ID UNIQUEIDENTIFIER, -- Menu item ID 
  t_mish_ID UNIQUEIDENTIFIER, -- Menu item shortcut ID         t_slgr_ID UNIQUEIDENTIFIER, -- Sales department ID           t_mvtp_ID UNIQUEIDENTIFIER, -- ID for menu unit of          measurement 
  t_Order INT, -- Index 
  t_DateBegin DATETIME, -- Start date of the action            t_Duration INT, -- Duration 
  t_PriceDiscount NUMERIC(18,4) DEFAULT 0, -- Discount         t_PriceMargin NUMERIC(18,4) DEFAULT 0, -- Markup 

-- Control fields 
  t_Price AS (t_PriceOriginal - t_PriceDiscount + t_PriceMargin), -- Price 
  t_ForUpdate BIT DEFAULT 0 -- Indicates that this item must be recalculated ) 

-- Accrued points 
CREATE TABLE #GuestDiscountPointOperations( 
  p_ID UNIQUEIDENTIFIER PRIMARY KEY, -- Entry ID 
  p_dspt_ID UNIQUEIDENTIFIER, -- Point type ID 
  p_Value INT DEFAULT 0 --  Number of points )