是否有人建议是否有任何规则在jdbc结果集中放置联合查询? 我在数据库中有一个联合查询,我得到了输出...但是当我试图在结果集中放置相同的Union查询时,
收到错误:ASA错误-131:'unionselect'附近的语法错误 在线...
任何人都可以建议我出错的地方......
jsp页面中的查询如下.....
String QueryString =
"select CONVERT(VARCHAR(7),[startdatetime],111) AS [year-month],nm.nameLine1 as CompanyName, sum(datediff(hour, startdatetime, enddatetime)) as total"
+" from servicerequestworklog as srl"
+" inner join ServiceRequest sr on srl.ServiceRequestId = sr.ServiceRequestId"
+" inner join Name nm on(sr.clientCustomerId = nm.customerId and nm.nameTypeId = 'OFIC')"
+" where (startdatetime >= '08-01-2011 00:00:00.000' and enddatetime <= '10-31-2011 00:00:00.000')"
+" group by CompanyName, [year-month]"
+"union"
+"select CONVERT(VARCHAR(7),[startdatetime],111) AS [year-month], 'ZZTOTAL' as CompanyName, sum(datediff(hour, startdatetime, enddatetime)) as total"
+" from servicerequestworklog as srl"
+"inner join ServiceRequest sr on srl.ServiceRequestId = sr.ServiceRequestId"
+" where (startdatetime >= '08-01-2011 00:00:00.000' and enddatetime <= '10-31-2011 00:00:00.000')"
+" group by [year-month]"
+"order by CompanyName, [year-month]" ;
答案 0 :(得分:1)
您可以使用PreparedStatement
(参数化查询)来避免这些类型的错误。我认为您必须在union
和select
字之间添加空格。