VB ORACLE 数据查询问题

来源:百度知道 编辑:UC知道 时间:2024/05/31 02:31:51
我在VB中执行这段SQL代码:查询是有记录的
dim xmcx as string
xmcx=""
txtSql = "select * from A_table where ADMISSION_DATE_TIME > to_date('" & DTPicker1.Value & "' ,'yyyy-mm-dd') and ADMISSION_DATE_TIME < to_date('" & CDate(DTPicker1.Value) + 1 & "' ,'yyyy-mm-dd') " & xmcx & ""
Set mrc = Nothing
Debug.Print txtSql
Set mrc = ExecuteSQL1(txtSql)
记录数是11条记录,说明上面的语句等是正确的。
但是以下查询记录为0,debug.print 复制到ORACLE查询是有3条记录的
dim xmcx as string
xmcx="李四"
txtSql = "select * from A_table where ADMISSION_DATE_TIME > to_date('" & DTPicker1.Value & "' ,'yyyy-mm-dd') and ADMISSION_DATE_TIME < to_date('" & CDate(DTPicker1.Value) + 1 & "' ,'yyyy-mm-dd') " & xmcx & ""
Set mrc = Nothing
Debug.Print txtSql
Set mrc = ExecuteSQL1(txtSql)
这是为什么?
备注:A_table 为ORACLE视图 视图正常 可以检索数据

" & xmcx & "" 这里错了,如果是字符变量要加单引号 '" & xmcx & "'"

txtSql = "select * from A_table where ADMISSION_DATE_TIME > to_date('" & DTPicker1.Value & "' ,'yyyy-mm-dd') and ADMISSION_DATE_TIME < to_date('" & CDate(DTPicker1.Value) + 1 & "' ,'yyyy-mm-dd') '" & xmcx & "'"

第二种情况,条件文最后是这样的吧。
and ADMISSION_DATE_TIME < to_date('20080808' ,'yyyy-mm-dd')李四
怎么可能执行呢。。。
没可能啊,没可能。。。

既然sql语句无错,建议直接贴出运行中的txtsql,这样看不出啥问题