求助,SQL语句语法错误
·语句原代码
StringBuilder strSql = new StringBuilder();
strSql.Append("select top " + pageSize);
strSql.Append(" " + fields + " from ");
strSql.Append(tableName + "where ");
strSql.Append(primaryKey + " ");
strSql.Append(((isAsc) ? "> " : "< "));
strSql.Append("( select ");
strSql.Append(((isAsc) ? "max" : "min"));
strSql.Append("(" + primaryKey);
strSql.Append(") from ( select top " + pageSize * (pageID - 1));
strSql.Append(" " + primaryKey + " from ");
strSql.Append(tableName + " ");
strSql.Append(((whereStr != "") ? "where " + whereStr + "" : ""));
strSql.Append(" order by " + orderKey + " ");
strSql.Append(((isAsc) ? "asc" : "desc"));
strSql.Append(" )) ");
strSql.Append(((whereStr != "") ? "and " + whereStr + "" : ""));
strSql.Append(" order by " + orderKey + " ");
strSql.Append(((isAsc) ? "asc" : "desc"));
在运行程序查询是提示:FROM 子句语法错误。
allCount记录总数
isAsc是否升序
primaryKey 主键
orderKey排序键
tableName表名
pageSize页大小
pageID页I
fields查询字段
whereStr查询条件
这条语句的意思是首先根据条件和排序获得结果集中的前(页大小X(页ID-1))条记录主键集合,然后根据查询条件和排序返回主键大于这些主键集合中的前pageSize条记录。
我把整条语句提出来:
"select top " + pageSize +" " + fields + " from " +tableName + "where " + primaryKey + " " +(isAsc) ? "> " : "< ") + "( select " +((isAsc) ? "max" : "min") +"(" + primaryKey + ") from ( select top " + (pageSize * (pageID - 1)) + " " + primaryKey + " from " +tableName + " " + ((whereStr != "") ? "where " + whereStr + "" : "") +" order by " + orderKey + " " + ((isAsc) ? "asc" : "desc") + " )) " + ((whereStr != "") ? "and " + whereStr + "" : "") +" order by " + orderKey + " " +((isAsc) ? "asc" : "desc")
大家帮忙分析一下,是哪里出错了?