在golang代码中使用sql查询获取语法错误。 golang中此SQL查询所需的正确语法:
rows, errQuery := dbCon.Query("SELECT B.LatestDate
,A.SVRName AS ServerName
,A.DRIVE
,A.TotalSpace_GB AS TotalSpaceGB
,(ISNULL(A.TotalSpace_GB, 0) - ISNULL(A.FreeSpace_GB, 0)) AS
UsedSpaceGB
,A.FreeSpace_GB AS FreeSpaceGB
,CASE
WHEN ((A.FreeSpace_GB / A.TotalSpace_GB) * 100) between 25 and
35
THEN 1
WHEN ((A.FreeSpace_GB / A.TotalSpace_GB) * 100) <= 25 THEN 2
ELSE 0
END AS WARNINGSTATUS
FROM Table_ServerDiskSpaceDetails A WITH (NOLOCK)
INNER JOIN (
SELECT SVRName
,MAX(Dt) LatestDate
FROM Table_ServerDiskSpaceDetails WITH (NOLOCK)
GROUP BY SVRName
) B ON A.Dt = B.LatestDate
AND A.SVRName = B.SVRName
ORDER BY WARNINGSTATUS DESC
,ServerName
,A.Drive")
答案 0 :(得分:5)
您的SQL语句有多行,但您没有使用正确的多行语法。正确的语法是:
someLongString := "Line 1 " + // Don't forget the trailing space
"Second line." // This is on the next line.
目前,您只是想在不同行上的一组引号之间填充所有内容。
编辑:Per @Kaedys在下面说,以下内容也有效,可能性能更高。
someLongString := `Line 1
Second line.`
答案 1 :(得分:0)
将第一个和最后一个“\”“更改为”“,或引用查询字符串的每一行,然后在每行之间添加”+“,如
"select" +
" *" +
" from" +
" table"