doushua7737 2017-05-08 17:11
浏览 74
已采纳

Golang SQL查询语法

Getting syntax erro with sql query in golang code. Required proper syntax for this SQL query in golang:

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")
  • 写回答

2条回答 默认 最新

  • dongni1892 2017-05-09 01:05
    关注

    Your SQL statement is on multiple lines, but you're not using the correct multi-line syntax. The correct syntax would be:

    someLongString := "Line 1 " +    // Don't forget the trailing space
                      "Second line." // This is on the next line.
    

    Currently you're just trying to stuff everything between a set of quotes on different lines.


    EDIT: Per as @Kaedys says below, the following also works and may be more performant.

    someLongString := `Line 1
                       Second line.`
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?