我正在使用github.com/denisenkom/go-mssqldb
软件包传递以下查询字符串:
q := `
SELECT TOP @p1
firstname,
lastname,
username,
phone,
email,
picture,
bio,
active,
joined
FROM (
SELECT
t2.first_name AS firstname,
t2.last_name AS lastname,
t1.username AS username,
t2.emp_phone AS phone,
t2.employee_email AS email,
t1.picture AS picture,
t1.bio AS bio,
CASE WHEN t2.employee_user_id IS NULL THEN 0
ELSE 1 END AS active,
t2.date_joined AS joined
FROM dbo.TBL_BIOS_ANALYSTS AS t1
LEFT JOIN dbo.TBL_HRMS_STAFF AS t2
ON t2.employee_user_id = t1.username
) AS t3
WHERE lastname=@p2 ORDER BY @p3`
我要传递以下参数:
args := []interface{}{
sql.Named("p1", 5),
sql.Named("p2", "chan"),
sql.Named("p3", "firstname"),
}
使用带有GUI的mssql客户端,查询运行良好,但是使用Go和该程序包,在执行db.Query(q, args...)
时出现以下错误:
mssql: Incorrect syntax near the keyword 'AS'.
帮助。