Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

Calling a Stored Procedure with Output Parameters

$
0
0
I have another PowerShell newbie question. I want to run a stored procedure from a PowerShell script and receive the resulting output parameter values. So basically, I would like to run the equivalent of the code below, but also receive the results. How might i do this? I'm sure Invoke-Sqlcmd has something to do with it, but I have no idea how to implement. USE [msdb]GODECLARE @return_value int, @job_name sysname, @job_id uniqueidentifier, @last_run_date int, @last_run_time int, @job_status int, @job_stat_desc varchar(100)SELECT @job_name = [NOTE: PowerShell script needs to pass this in.]EXEC @return_value = [dbo].[sp_RunSQLAgentJob] @job_name = @job_name OUTPUT, @job_id = @job_id OUTPUT, @last_run_date = @last_run_date OUTPUT, @last_run_time = @last_run_time OUTPUT, @job_status = @job_status OUTPUT, @job_stat_desc = @job_stat_desc OUTPUTSELECT @job_name as N'@job_name', @job_id as N'@job_id', @last_run_date as N'@last_run_date', @last_run_time as N'@last_run_time', @job_status as N'@job_status', @job_stat_desc as N'@job_stat_desc'SELECT 'Return Value' = @return_valueGO

Viewing all articles
Browse latest Browse all 467

Trending Articles