Database Newbie Question: Calling a Stored Procedure that returns values?

2,400 views
Skip to first unread message

sc28

unread,
Jun 12, 2015, 1:21:55 PM6/12/15
to golan...@googlegroups.com
It's not clear to me the proper way to call a stored procedure (MS SQL)

If I were to use the Query function, would do something like this:

row, err := d.QueryRow("Select ... From ... Where...")

I want to call an existing stored procedure that takes in a parameter and returns a row - is it the same, i.e.,

row, err := d.QueryRow("sp_GetTheData ?", :getThisRecord)

I'm not sure how to bind the "getThisRecord" parameter to send it to the stored procedure "sp_GetTheData"

TIA!

Daniel Theophanes

unread,
Jun 12, 2015, 1:33:04 PM6/12/15
to golan...@googlegroups.com
Which driver are you using?

You may need to use exec:
d.QueryRow("exec sp_GetTheData ?", recordId)

-Daniel

sc28

unread,
Jun 15, 2015, 6:33:51 PM6/15/15
to golan...@googlegroups.com
Thanks - I'm using the ms sql driver "github.com/denisenkom/go-mssqldb" - got things working as you showed.

Minor question - why QueryRow and not Exec (if the stored procedure is for, say updating a value - yes, I know I'd be ignoring any returned errors, just trying to properly use the correct constructs).

Daniel Theophanes

unread,
Jun 15, 2015, 6:36:40 PM6/15/15
to sc28, golan...@googlegroups.com
If you don't want a return value back, yeah, use Exec. If you DO want a return value back, use Query or QueryRow.

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/uOQywLYeRv4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages