PANTHEON™ Help

 Toc
 PANTHEON Help - Welcome
[Collapse]PANTHEON
 [Collapse]Guides for PANTHEON
  [Expand]Guide for PANTHEON
  [Expand]Guide for PANTHEON Retail
  [Expand]Guide for PANTHEON Vet
  [Expand]Guide for PANTHEON Farming
 [Collapse]User Manuals for PANTHEON
  [Collapse]User Manual for PANTHEON
   [Collapse]Getting Started
     Dictionary of terms
     First steps with PANTHEON
    [Expand]Using PANTHEON at Tecta, a fictional company
    [Expand]Instructions for Ensuring Compliance of PANTHEON with SAS
    [Expand]PANTHEON Installation
    [Collapse]PANTHEON System
     [Expand]PANTHEON System data
     [Collapse]MS SQL Server
       Download and install MS SQL Server
       Upgrading MS SQL Server to 2019 or 2022
       MS Management Studio - Download and install
       Restoring database onto SQL server
       Adding users to server level (AddUser_PAX)
       Installing SQL for external access
       Installing PANTHEON clients
       Nastavitve MS SQL strežnika za večja Pantheon™ oko
       Changing SQL Sort Order
      [Expand]MS SQL Server Security
      [Expand]Useful SQL Queries
       SQLExecute
      [Collapse]SQL Server Jobs
       [Collapse]Refresh Stock
         Refresh Stock Job Using Enterprise Manager
         Refresh Stock Job Using T-SQL Commands
        E-Mail Reminders for Overdue Receivables
        DB Maintenance Plan
     [Expand]Microsoft Windows Utilities
     [Expand]Security Policy
     [Expand]Database Administration
    [Expand]PANTHEON Basics
    [Expand]PANTHEON Help
    [Expand]Materials and Goods Movements
    [Expand]Assigning Identifiers
    [Expand]Frequently asked questions about Pantheon (F.A.Q.)
    [Expand]Archive
   [Expand]User Manual for eBusiness
   [Expand]Settings
   [Expand]Orders
   [Expand]Goods
   [Expand]Manufacturing
   [Expand]Service
   [Expand]Help
   [Expand]Personnel
   [Expand]Financials
   [Expand]Analytics
  [Expand]User Manual for PANTHEON Retail
  [Expand]User manual for PANTHEON Vet
  [Expand]User Manual for PANTHEON Farming
[Collapse]PANTHEON Web
 [Collapse]Guides for PANTHEON Web
  [Expand]Guide for PANTHEON Web Light
  [Expand]Guide for PANTHEON Web Terminal
  [Expand]Guide for PANTHEON Web Legal
  [Expand]Old products Archive
 [Collapse]User Manuals for PANTHEON Web
  [Expand]Getting started PANTHEON Web
  [Expand]User Manual for PANTHEON Web Light
  [Expand]User Manual for PANTHEON Web Terminal
  [Expand]User Manual for PANTHEON Web Legal
  [Expand]Old products Archive
[Collapse]PANTHEON Granules
 [Collapse]Guides for PANTHEON Granules
  [Expand]Personnel Granule
  [Expand]Travel Orders Granule
  [Expand]Documents and Tasks Granule
  [Expand]Dashboard Granule
  [Expand]B2B Orders Granule
  [Expand]Field Service Granule
  [Expand]Fixed Assets Inventory Granule
  [Expand]Warehouse Inventory Granule
 [Collapse]User Manuals for PANTHEON Granules
  [Expand]Getting started
  [Expand]Personnel Granule
  [Expand]Travel Orders Granule
  [Expand]Documents and Tasks Granule
  [Expand]B2B Orders Granule
  [Expand]Dashboard Granule
  [Expand]Field Service Granule
  [Expand]Fixed Assets Inventory Granule
  [Expand]Warehouse Inventory Granule
  [Expand]Archive
[Expand]User Site

Load Time: 390.6337 ms
"
  2549 | 2939 | 342031 | Updated
Label

Refresh Stock Job Using T-SQL Commands

Refresh Stock Job Using T-SQL Commands

Refresh Stock Job Using T-SQL Commands

If Enterprise Manager is not available to create a Refresh Stock job, you can achieve the same with T-SQL commands.

The job code below will make a full stock refresh. You can remove steps that aren't needed.

Edit the following to suit your configuration.

  • ServerName - change this to the server name and instance where your database is running.
  • DBname - change this to the database name where you want to refresh stock.

Replace all occurences of both with your configuration.

 

begin transaction

declare
  @JobID binary(16),
  @ReturnCode int

set nocount on
select @ReturnCode = 0

-- create job header
execute @ReturnCode = msdb.dbo.sp_add_job @job_id = @JobID output,
        @job_name = N'Refresh stock - daily', @enabled = 1,
        @description = N'',
        @category_name = N'[Uncategorized (Local)]', 
        @notify_level_eventlog = 2, @delete_level= 0
if (@@ERROR <> 0 OR @ReturnCode <> 0)
  goto QuitWithRollback

-- step 1 - refresh serial numbers
execute @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID,
        @step_id = 1, @step_name = N'Refresh serial numbers',
        @command = N'exec dl_PA_ObrProm_StetjeSerialNo '''', null, null
          exec dl_PA_ObrProm_StatusSerialNo ''''', @database_name = N'DBname',
        @server = N'', @database_user_name = N'', @subsystem = N'TSQL',
        @cmdexec_success_code = 0, @flags = 0, @retry_attempts = 0,
        @retry_interval = 1, @output_file_name = N'', @on_success_step_id = 0,
        @on_success_action = 3, @on_fail_step_id = 0, @on_fail_action = 2
if (@@ERROR <> 0 OR @ReturnCode <> 0)
  goto QuitWithRollback

-- step 2 - recalculate prices
execute @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID,
        @step_id = 2, @step_name = N'Recalculate prices',
        @command = N'exec dl_PA_ObrProm_CalcCen '''', null, null, ''''
          exec dl_PA_ObrProm_CalcLastCen '''', null, null, ''''
          exec dl_PA_ObrProm_PreracunNabCenZbirno ''''',
        @database_name = N'DBname', @server = N'', 
        @database_user_name = N'',@subsystem = N'TSQL',
        @cmdexec_success_code = 0, @flags = 0, @retry_attempts = 0,
        @retry_interval = 1, @output_file_name = N'', @on_success_step_id = 0,
        @on_success_action = 3, @on_fail_step_id = 0, @on_fail_action = 2
if (@@ERROR <> 0 OR @ReturnCode <> 0)
  goto QuitWithRollback

-- step 3 - refresh stock
execute @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID,
        @step_id = 3, @step_name = N'Refresh stock',
        @command = N'exec dl_PA_ObrProm_ObnovitevZaloge ''''',
        @database_name = N'DBname', @server = N'', 
        @database_user_name = N'', @subsystem = N'TSQL',
        @cmdexec_success_code = 0, @flags = 0, @retry_attempts = 0,
        @retry_interval = 1, @output_file_name = N'', @on_success_step_id = 0,
        @on_success_action = 3, @on_fail_step_id = 0, @on_fail_action = 2
if (@@ERROR <> 0 OR @ReturnCode <> 0)
  goto QuitWithRollback

-- step 4 - refresh document headers
execute @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID,
        @step_id = 4, @step_name = N'Refresh document headers',
        @command = N'exec dl_PA_ObrProm_PreracunBlagajna null, null
          exec dl_PA_ObrProm_PreracunDenar null, null
          exec dl_PA_ObrProm_PreracunNaroc null, null
          exec dl_PA_ObrProm_PreracunNarocOdprem '''', null, null
          exec dl_PA_ObrProm_PreracunPromet null, null, ''F''',
        @database_name = N'DBname', @server = N'', 
        @database_user_name = N'', @subsystem = N'TSQL',
        @cmdexec_success_code = 0, @flags = 0, @retry_attempts = 0,
        @retry_interval = 1, @output_file_name = N'', @on_success_step_id = 0,
        @on_success_action = 1, @on_fail_step_id = 0, @on_fail_action = 2
if (@@ERROR <> 0 OR @ReturnCode <> 0)
  goto QuitWithRollback

-- write initial step into job
execute @ReturnCode = msdb.dbo.sp_update_job @job_id = @JobID, @start_step_id = 1
if (@@ERROR <> 0 OR @ReturnCode <> 0)
  goto QuitWithRollback

-- set up schedule
execute @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id = @JobID,
        @name = N'Vsakodnevno izvajanje ob 01.00', @enabled = 1,
        @freq_type = 4, @active_start_date = 20020103,
        @active_start_time = 10000, @freq_interval = 1,
        @freq_subday_type = 1, @freq_subday_interval = 0,
        @freq_relative_interval = 0, @freq_recurrence_factor = 1,
        @active_end_date = 99991231, @active_end_time = 235959
if (@@ERROR <> 0 OR @ReturnCode <> 0)
  goto QuitWithRollback

-- initialize job
execute @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @JobID,
        @server_name = N'ServerName', @automatic_post = 0
if (@@ERROR <> 0 OR @ReturnCode <> 0)
  goto QuitWithRollback

select @JobID
if (@@ERROR <> 0 OR @ReturnCode <> 0)
  goto QuitWithRollback

commit transaction
goto   EndSave

QuitWithRollback:
  IF (@@TRANCOUNT > 0) rollback transaction
EndSave:

 

The same notes apply for this job as for the job created using Enterprice Manager.



 

Rate this topic
Was this topic usefull?
Comments
Comment will also bo visible in forum!