字符串常量必须以双引号SQL报告结束

时间:2016-11-03 20:43:37

标签: sql vb.net tsql reporting

以下是我在SQL Server Business Studio中完成的sql报告的查询,并且我一直收到关于此行Dim SelectClause as System.String = ""上的双引号的错误

我尝试了一些东西,但是我得到了重复的错误。

任何帮助都将不胜感激。

Function getSelectClause(ByVal startDate as DateTime, ByVal endDate as  DateTime) as String
  Dim SelectClause as System.String =  "" 

SelectClause ="SELECT Define.meterName, SUM(Reading.volume) AS [Total Volume], MIN(Reading.time) AS [Month]

   FROM [Reading] INNER JOIN Define ON Reading.meterId = Define.meterId

   WHERE (Reading.[time] >= " & startDate & " AND Reading.[time]< " & endDate & ")
   AND Define.meterName IN ('007080')
   AND (Reading.dataQuality = '11' OR 
                  Reading.dataQuality = '10') AND (Reading.auditVersion = '0') 
   GROUP BY Define.meterName"

   return SelectClause
End Function

1 个答案:

答案 0 :(得分:1)

SSRS使用VB作为自定义函数的语言,其语法与SQL不同。 VB不支持像SQL那样的多行语句。您需要使用" + _结束每一行并使用"开始继续,并更改添加日期字符串的方式:

    Function getSelectClause(ByVal startDate as DateTime, ByVal endDate as  DateTime) as String
Dim SelectClause as System.String =  "" 

SelectClause ="SELECT Define.meterName, SUM(Reading.volume) AS [Total Volume], " + _
"  MIN(Reading.time) AS [Month]" + _
"   FROM [Reading] INNER JOIN Define ON Reading.meterId = Define.meterId" + _
"   WHERE (Reading.[time] >= '" + startDate + "' AND Reading.[time]<  '" + endDate+ "')" + _
"  AND Define.meterName IN ('007080')" + _
"  AND (Reading.dataQuality = '11' OR " + _
"                  Reading.dataQuality = '10') AND (Reading.auditVersion = '0') " + _
"  GROUP BY Define.meterName"

return SelectClause