2007年6月28日 星期四

Calling Stored Procedures from Rails

Anyway, to call a stored procedure in Rails I used the following:

sql = "declare @result int \n"

sql += "declare @some_value uniqueidentifier \n"

sql += "exec @result = my_stored_procedure @input1 = 'hello', @input2 = 'world', @output = @some_value output \n"

sql += "select @result\n" # change this to select @some_value if you want to access the output parameter

result = connection.select_value(sql)


EX:
sql = "declare @iid int "
sql += "exec sp_test_insert_02 'aabbccdd', @iid output "
sql += "select @iid "
@res = ActiveRecord::Base.connection.select_value(sql)

沒有留言: