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.`
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • doubu1950 2017-06-17 05:04
    关注

    change both your first and last "\"" to "`", or quote your each line of the query string and then add a "+" between each line like

    "select" +
    " *" +
    " from" +
    " table"
    
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 win11安卓子系统打开谷歌登录不了切使用浏览器显示处于离线状态
  • ¥15 三维直角坐标系下,给定一个平面内四个点坐标,如何将四个点逆时针排序
  • ¥15 UnityWebRequest访问内网地址502
  • ¥20 Python语言来实现牛顿法(Newton's Method)解决非线性(系统)方程的问题。
  • ¥15 matlab控制工业相机采集图像
  • ¥25 R里做折线图和柱状图
  • ¥20 使用kokkos移植项目,遇到问题
  • ¥15 求该问题的Matlab代码
  • ¥15 python下使用pdpbox为何提示has no attribute 'pdp_isolate'?
  • ¥15 求java web病房管理系统项目,用netbeans做的