As per my previous post about activating xp_cmdshell for executing command line application in SQLServer there is some additional needs other than just executing, we need to get triggered value such as new value or updated or deleted as argument in command line that we want to execute.
we need do some trick because we cannot directly put the trigger value directly on string that contain command that we want to be ran. so the value will be hold in some variable. for example i want to get the value of new project’s name that will be sent to another application with it’s API through Python Script.
CREATE TRIGGER sendToAPI ON projects FOR INSERT AS BEGIN DECLARE @project_name NVARCHAR(MAX) DECLARE @runcmd VARCHAR(100) SELECT @project_name = INSERTED.name FROM INSERTED SET @runcmd = 'C:\Python27\python.exe C:/pyscripts/inputProject.py '+@project_name EXEC master..xp_cmdshell @runcmd end
Happy coding 🙂