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

Posted

技术标签:

【中文标题】字符串常量必须以双引号结尾 SQL 报告【英文标题】:String Constant must End with double quote SQL report 【发布时间】:2016-11-03 20:43:36 【问题描述】:

下面是我在 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

【问题讨论】:

您使用的是哪个 DBMS? 【参考方案1】:

s-s-rS 使用 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

【讨论】:

以上是关于字符串常量必须以双引号结尾 SQL 报告的主要内容,如果未能解决你的问题,请参考以下文章

R语言 字符串

常量不加引号报错提示‘参数**没有默认值’

常量变量关键字标识符的理解

Oracle单引号问题

字符串与字符串函数 - 字符串 & 字符串输入

multipart 中的@Part 以双引号发送字符串参数