How to execute MSSQL stored procedure and take the result in GORM

List of Objects or Map

Comment From: a631807682

gorm does not support the clause of the stored procedure, you can execute it through Exec and Raw

https://gorm.io/docs/sql_builder.html#Connection

    m := make(map[string]interface{}, 0)
    DB.Connection(func(tx *gorm.DB) error {
        tx.Exec(`DROP PROCEDURE IF EXISTS sp_query;`)
        tx.Exec(`
            CREATE PROCEDURE sp_query (IN p1 INT, IN p2 varchar(100), p3 NUMERIC(10,4))
            BEGIN    
            SELECT p1,  p2, p3;
            END
        `)
        return tx.Raw("call sp_query(?,?,?)", 2, "123", 4).Scan(&m).Error
    })