Skip to content

Instantly share code, notes, and snippets.

@SeriousM
Created May 12, 2014 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeriousM/6631c6ff2bc4033b0a5a to your computer and use it in GitHub Desktop.
Save SeriousM/6631c6ff2bc4033b0a5a to your computer and use it in GitHub Desktop.
Sql Example of parameter directions in combination with C#
if exists(select * from sys.procedures where name = 'test_proc')
begin
drop procedure test_proc
end
go
create procedure test_proc
@in int,
@out int output,
@inout int output
as
begin
print '@in was ' + convert(varchar(max), @in) + ' and set it to 11'
set @in = 11
print '@out was ' + convert(varchar(max), @out) + ' and set it to 22'
set @out = 22
print '@inout was ' + convert(varchar(max), @inout) + ' and set it to 33'
set @inout = 33
print 'returning 44'
return 44
end
go
declare @in int = 1, -- ParameterDirection.Input
@out int = 2, -- ParameterDirection.Output
@inout int = 3, -- ParameterDirection.InputOutput
@retval int = 4 -- ParameterDirection.ReturnValue
exec @retval = test_proc @in = @in, @out = @out output, @inout = @inout output
select @in, @out, @inout, @retval
go
if exists(select * from sys.procedures where name = 'test_proc')
begin
drop procedure test_proc
end
go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment