Skip to content

Instantly share code, notes, and snippets.

@aadennis
Created April 21, 2020 19:45
Show Gist options
  • Save aadennis/7afd238328882c1d5fbae8848aefba1e to your computer and use it in GitHub Desktop.
Save aadennis/7afd238328882c1d5fbae8848aefba1e to your computer and use it in GitHub Desktop.
# CREATE PROCEDURE DemoSp
# -- Add the parameters for the stored procedure here
# @in int,
# @out int out
# AS
# BEGIN
# SET NOCOUNT ON;
# select @out = @in * 2;
# SELECT @in, @out
# END
function Run-StoredProcedureWithOutVar($inValue) {
$statement = @"
DECLARE @outVar bigint;
EXEC a_db1.dbo.[DemoSp] @in = '${inValue}'
, @out = @outVar output;
SELECT @outVar as arbitraryOutVar
"@
$params = @{
Query = $statement -f $inValue
}
$results = Invoke-Sqlcmd -Serv localhost -U sa -P TheDemo @params -Verbose
write-Host "In value: [$inValue]; Out value: [$($results.arbitraryOutVar)]"
}
Run-StoredProcedureWithOutVar 33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment