# Help with executing sql server stored procedure from ecto

**URL:** <https://forum.elixirforum.com/t/help-with-executing-sql-server-stored-procedure-from-ecto/19802>\
**Category:** Questions\
**Tags:** ecto, database\
**Created:** [January 30, 2019, 10:28pm UTC](https://forum.elixirforum.com/t/help-with-executing-sql-server-stored-procedure-from-ecto/19802 "2019-01-30T22:28:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanswapp](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ryanswapp/32/304_2.png) [@ryanswapp](https://forum.elixirforum.com/u/ryanswapp)\
**Post date:** [January 30, 2019, 10:28pm UTC](https://forum.elixirforum.com/t/help-with-executing-sql-server-stored-procedure-from-ecto/19802/1 "2019-01-30T22:28:58Z")

</div>

I have run into a little issue and am not sure what I’m doing wrong. My app is connected to an external sql server database (database for another app) via Tds Ecto. I’m trying to execute a stored procedure using Repo.query but nothing is being returned and no errors are reported. Here is my code:

```
case SARepo.query("""
  sma_SP_Get_CaseNotes @CaseID=@1;
""", [case_id]) do 
  {:ok, %Tds.Result{columns: columns, rows: rows}} ->
    {:ok, Helpers.map_rows_to_columns(rows, columns)}
  {:error, %Tds.Error{} = error} ->
    {:ok, error}
end

```

When I run the sma\_SP\_Get\_CaseNotes procedure in DataGrip it works fine and returns the data I want. I’ve run a trace in Sql Server Data Profile and the difference between the datagrip call and the Ecto call appears to be that Ecto is making an RPC type call whereas datagrip is doing something a little different that I am unfamiliar with. Anyone see an obvious mistake I’m making?

---

<div class="post-metadata">

**Author:** ![raymondsiu](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/raymondsiu/32/11137_2.png) [@raymondsiu](https://forum.elixirforum.com/u/raymondsiu)\
**Post date:** [December 30, 2019, 6:16pm UTC](https://forum.elixirforum.com/t/help-with-executing-sql-server-stored-procedure-from-ecto/19802/2 "2019-12-30T18:16:15Z")

</div>

Try adding the `exec` command before the name of the stored procedure.  
When you write Transact-SQL, that’s the way to execute stored procedures so I am thinking it might be the same way in your case.

---

<div class="post-metadata">

**Author:** ![ryanswapp](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ryanswapp/32/304_2.png) [@ryanswapp](https://forum.elixirforum.com/u/ryanswapp)\
**Post date:** [December 30, 2019, 6:30pm UTC](https://forum.elixirforum.com/t/help-with-executing-sql-server-stored-procedure-from-ecto/19802/3 "2019-12-30T18:30:40Z")

</div>

The issue was actually that I needed to add:

```elixir
SET NOCOUNT ON;

```

To the top of the query so that it would return a result.
