日期:2014-05-18  浏览次数:20399 次

关于多表查询的sql语句,在线等~
有2个表body和B
body的字段为IndexID,CA,LA,BId
b的字段为No,ID,Year,Month
BODY中BID的数据与B表ID字段数据一致
现在要从B表中查寻NO,BODY表中查询INDEXID,CA,LA的数据,写了如下的SQL语句,ASP编译中显示
错误类型:
Microsoft   OLE   DB   Provider   for   SQL   Server   (0x80040E14)
在关键字   'and '   附近有语法错误。
SQL语句如下:
SELECT   B1.No,Body.IndexID,Body.CA,Body.LA   From   Body   Inner       Join   (Select     No,Id   From   B   where     B.Type   = 'B202 'and   B.Year   = "&DateYear& "and   B.Month   = "&DateMonth& ")B1   On   B1.Id=Body.BId


------解决方案--------------------
---try---

SELECT B1.No,Body.IndexID,Body.CA,Body.LA
From Body Inner Join
(Select No,Id From B where B.Type = 'B202 ' and B.Year = ' "&DateYear& " ' and B.Month = ' "&DateMonth& " ') B1 On B1.Id=Body.BId
------解决方案--------------------
SELECT B1.No,Body.IndexID,Body.CA,Body.LA
From Body Inner Join
(Select No,Id From B where B.Type = 'B202 ' and B.Year = ' "&DateYear& " ' and B.Month = ' "&DateMonth& " ') B1 On B1.Id=Body.BId