sql语句的语法错误,帮忙看一下

ZJM2032 2010-07-27 10:04:37
select top 25 a.[ID],a.[OrderID],b.[Name] as pName,a.[Quantity],a.[Sum],a.[Date],a.IsPay,c.[Name] as mName from [Order] a left outer join Product b on a.ProductID=b.ProductID left outer join Member c on a.MemberID=c.MemberID where 1=1 order by a.[ID] Desc

就是这样,就关联一下产品表读产品名称,然后关联一下会员表读会员名字
提示语法错误(操作符丢失)
我不知道什么原因,帮忙看一下啊
...全文
115 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿双2009 2010-07-27
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 jianming2032 的回复:]
引用 11 楼 luols 的回复:
Access不支持left outer join这样的语法

参考
http://www.cnblogs.com/wayne1017/archive/2006/09/15/505030.html

谢谢,access比sql数据库麻烦多了
[/Quote]

Sorry,Access支持这样的语法,改下试试:

select a.ID,a.OrderID,b.[Name] as pName,a.Quantity,a.Sum,a.[Date],a.IsPay,c.Name as mName
from
([Order] a left outer join Product b on a.ProductID=b.ProductID)
left outer join Member c on a.MemberID=c.MemberID
where 1=1 order by a.ID Desc
ZJM2032 2010-07-27
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 luols 的回复:]
Access不支持left outer join这样的语法

参考
http://www.cnblogs.com/wayne1017/archive/2006/09/15/505030.html
[/Quote]
谢谢,access比sql数据库麻烦多了
阿双2009 2010-07-27
  • 打赏
  • 举报
回复
Access不支持left outer join这样的语法

参考
http://www.cnblogs.com/wayne1017/archive/2006/09/15/505030.html
ZJM2032 2010-07-27
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 mayonglong 的回复:]
注意Access的语法会有不同~
[/Quote]

请问哪里不同,应该怎么改呢这个查询,调试出来的语句是
select top 25 a.ID,a.OrderID,b.Name as pName,a.Quantity,a.Sum,a.[Date],a.IsPay,c.Name as mName from [Order] a left outer join Product b on a.ProductID=b.ProductID left outer join Member c on a.MemberID=c.MemberID where 1=1 order by a.ID Desc
执行的时候出错的
mayonglong 2010-07-27
  • 打赏
  • 举报
回复
注意Access的语法会有不同~
ZJM2032 2010-07-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 luols 的回复:]
引用 4 楼 jianming2032 的回复:
引用 2 楼 luols 的回复:
我这边提示“命令已成功完成。”


不会吧,哦,我用的是access数据库,是不是access不支持这种语句的啊?


Access的话,改成这样试试

SQL code

select top 25
a.[ID],a.[OrderID],b.[Name] as pName,a.[Qu……
[/Quote]

呵呵,我原来也是用这种方式,但是考虑到表多了容易乱,所以改用这种方式,原来的代码是这样的
public DataSet GetList(int intPageSize, int intPageIndex, string strWhere, string strOrderField, string strOrderDirection)
{
StringBuilder strSql = new StringBuilder();
if (intPageIndex == 1)
{
strSql.Append("select top " + intPageSize.ToString() + " a.ID,a.OrderID,b.Name as pName,a.Quantity,a.Sum,a.[Date],a.IsPay,c.Name as mName from [Order] a");
strSql.Append(" left outer join Product b on a.ProductID=b.ProductID ");
strSql.Append(" left outer join Member c on a.MemberID=c.MemberID ");
strSql.Append(" where 1=1 " + strWhere + " order by a." + strOrderField + " " + strOrderDirection + "");
}
else
{
strSql.Append("select top " + intPageSize.ToString() + " a.ID,a.OrderID,b.Name as pName,a.Quantity,a.Sum,a.[Date],a.IsPay,c.Name as mName from [Order] a");
strSql.Append(" left outer join Product b on a.ProductID=b.ProductID ");
strSql.Append(" left outer join Member c on a.MemberID=c.MemberID ");
strSql.Append(" where a.[" + strOrderField + "] not in(select top " + (intPageIndex - 1) * intPageSize + " [" + strOrderField + "] from [Order] where 1=1 " + strWhere + " order by [" + strOrderField + "] desc) " + strWhere + " Order by a.[" + strOrderField + "] " + strOrderDirection + "");
}
return DbHelperSQL.Query(strSql.ToString());
}
阿双2009 2010-07-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 jianming2032 的回复:]
引用 2 楼 luols 的回复:
我这边提示“命令已成功完成。”


不会吧,哦,我用的是access数据库,是不是access不支持这种语句的啊?
[/Quote]

Access的话,改成这样试试

select top 25
a.[ID],a.[OrderID],b.[Name] as pName,a.[Quantity],a.[Sum],a.[Date],a.IsPay,
c.[Name] as mName
from [Order] a,Product b,Member c
where a.ProductID=b.ProductID and a.MemberID=c.MemberID
order by a.[ID] Desc
nauhil 2010-07-27
  • 打赏
  • 举报
回复
我按你的方式写了个查询,没有显示错误
ZJM2032 2010-07-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 luols 的回复:]
我这边提示“命令已成功完成。”
[/Quote]

不会吧,哦,我用的是access数据库,是不是access不支持这种语句的啊?
ZJM2032 2010-07-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 nauhil 的回复:]
where 1=1?

这句是啥意思?
[/Quote]

这在这里是没用的,就加了一个where关键字,因为后面有时候会加and条件,所以防止出错啊
阿双2009 2010-07-27
  • 打赏
  • 举报
回复
我这边提示“命令已成功完成。”
nauhil 2010-07-27
  • 打赏
  • 举报
回复
where 1=1?

这句是啥意思?
ZJM2032 2010-07-27
  • 打赏
  • 举报
回复
谢谢,我去搜了下access的left outer join就知道了,要加括号的,不能跟sql一样并列着来

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧