Created
April 21, 2020 19:45
-
-
Save aadennis/7afd238328882c1d5fbae8848aefba1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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