一个简单的SQL语(50分)

  • 主题发起人 主题发起人 say-rise
  • 开始时间 开始时间
S

say-rise

Unregistered / Unconfirmed
GUEST, unregistred user!
sql.Text := 'select sbjj.cntr_no as 箱号,sbjj.date as 时间 from sbjj where cntr_no not in (select cntr_no from cmt ),date between '''+str1+''' and '''+str2+''''
 
那里有错,请指教
 
),date ---> ) and date ....?

先在数据库里测试SQL语句正确与否
 
把date between前面的,换成and,还有最好使用别名,不要直接用表名,而且用的话,设计到的地方都用,不要有的用有的不用
 
cntr_no,date都是sbjj中的字段
 
sql.Text := 'select sbjj.cntr_no as 箱号,sbjj.date as 时间 from sbjj where cntr_no not in (select cntr_no from cmt ) and date between '''+str1+''' and '''+str2+'''' ^
 
data between前面的','换成'and '
 
date between 前面当然要有and
 
还是不行啊
 
sql.Text := 'select sbjj.cntr_no as 箱号,sbjj.date as 时间 from sbjj where (cntr_no not in (select cntr_no from cmt )) and (date between '''+str1+''' and '''+str2+''')' ^
 
我查找的是ACESS中的数据库
 
你应该最好把报什么错发上来吧~
 
楼主的数据库应该是Access吧。如果是,那么请注意,date最好不要用来做字段,跟程序中的函数有冲突,应该是用FDate来代替。另外,date between 前面使用and,不要用逗号。你再看看行不?
 
应该是data的问题 因为data是保留字
 
data改成[data]
 
sql.Text := 'select sbjj.cntr_no as 箱号,sbjj.date as 时间 from sbjj where sbjj.cntr_no not in (select cntr_no from cmt )) and (date between '''+str1+''' and '''+str2+''')';
 
....+'CDate('''+str1+''')'+.....

另外最好不要用''''的形式,用quotedStr函数
 
最好不用between and ,用< >
 
not in 和 between 不能混用

sql.Text := 'select sbjj.cntr_no as 箱号,sbjj.date as 时间 from (select * from sbjj where date between '''+str1+''' and '''+str2+''' ) where cntr_no not in (select cntr_no from cmt )'
 
估计是以下两条产生的错误
1.查询语句的日期格式不对(SQL Server与Access的区别)
2.添加And
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
872
DelphiTeacher的专栏
D
后退
顶部