ADO中出现IDispatch error #3092的一种情况

IDispatch error #3092    表示sql执行语句有语法错误,一般容易检查。下面是一个该错误的例子:

 

sql1=_T("SELECT *,DATEPART(yyyy,Student_InDate) as Student_InYearDate FROM Table_Student order by Student_ID");  //正确

 

sql2=_T("SELECT *,DATEPART(yyyy,Student_InDate) as Student_InYearDate FROM Table_Student  order by Student_ID WHERE Table_Student.Student_ID='"+m_sID+"' "); //错误

 

sql3=_T("SELECT *,DATEPART(yyyy,Student_InDate) as Student_InYearDate FROM Table_Student  WHERE Table_Student.Student_ID='"+m_sID+"' order by Student_ID "); //正确

 

其中sql1是没问题的,sql2提示错误,原因是  order by 排序语句应当放在语句的最后。sql2的正确表达形式如sql3所示。

你可能感兴趣的:(sql,table)