Skip to content

Instantly share code, notes, and snippets.

@JosiahSiegel
Last active June 2, 2017 17:17
Show Gist options
  • Save JosiahSiegel/19c77e045c906f7f97be to your computer and use it in GitHub Desktop.
Save JosiahSiegel/19c77e045c906f7f97be to your computer and use it in GitHub Desktop.
#Rails Call stored procedure and retrieve return value
class StoredProcedure
def self.return_value name, *args
ActiveRecord::Base.connection_pool.with_connection do |connection|
args = args.map{|e| connection.quote e}
output = connection.select_all("Declare @status int;" +
"EXEC @status = #{name} #{args.join(',')};" +
"select @status as status;")
return_value = Hash[*output]
return_value["status"]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment