How do you get the output parameter value from a SQL stored proc in golang using sqlx.?

1.1k Views Asked by At

How do you get the output parameter value from a SQL stored proc in golang.......does anyone have an example please...using sqlx i've tried

(
    @grade INT,
    @user_id CHAR(10),
    @card_number BIGINT OUT

db.Exec("call dbo.spGetNext 7,sSSSSS,@card_number;SELECT @card_number;")```


get ERROR - mssql: Must declare the scalar variable "@card_number".
1

There are 1 best solutions below

0
On

Try using the QueryRowx:

QueryRowx queries the database and returns an *sqlx.Row

Any placeholder parameters are replaced with supplied args

something like this:

grade := 10
userID := "123"
var cardNumer int32

if err = db.QueryRowx("CALL dbo.spGetNext(?, ?)", grade, userID).Scan(&cardNumer); err != nil && err != sql.ErrNoRows {
    panic(err)
}