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")
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.`
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"